button-lock
button-lock copied to clipboard
button-lock-set-button causes python/ipython repl to be read-only
I think button-lock-set-button is interacting with org-mode in a strange, and undesirable way.
The issue is that in org-mode, if I have a python src block that uses a session, I can type C-c C-v C-z to access the REPL for that session. However, if I have called a button-lock-set-button command before starting the session, then the REPL buffer is read-only, and unusable. I don't know why button-lock does that since there is no obvious read-only code in button-lock, but if I don't use it then everything is fine.
Steps to reproduce:
Use this init.el file:
(setq user-emacs-directory "./sandbox/")
(require 'package)
(setq package-archives
'(("org" . "https://orgmode.org/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(package-initialize)
(package-refresh-contents)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
(use-package org-plus-contrib)
(use-package button-lock)
(setq org-confirm-babel-evaluate nil)
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(python . t)
(python . t)))
Create these two org files:
test.org:
Run this block and then C-c C-v C-z opens repl fine.
#+BEGIN_SRC python :results output org drawer :session
5 # cursor here, type C-c C-v C-z and get interactive repl
#+END_SRC
#+RESULTS:
:RESULTS:
7)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
5
python.el: native completion setup loaded
:END:
Now run this one to add a hook function that defines a button..
#+BEGIN_SRC emacs-lisp
(require 'button-lock)
(global-button-lock-mode +1)
(add-hook 'org-mode-hook
(lambda ()
(button-lock-set-button
"<run>"
(lambda () (interactive) (message "running"))
:face (list 'link)
:help-echo "Click to run me")))
#+END_SRC
#+RESULTS:
| (lambda nil (button-lock-set-button <run> (lambda nil (interactive) (message running)) :face (list (quote link)) :help-echo Click to run me)) | #[0 \300\301\302\303\304$\207 [add-hook change-major-mode-hook org-show-block-all append local] 5] | #[0 \300\301\302\303\304$\207 [add-hook change-major-mode-hook org-babel-show-result-all append local] 5] | org-babel-result-hide-spec | org-babel-hide-all-hashes | org-eldoc-load |
Click on this to open it.
[[./test2.org]]
test2.org
<run>
#+BEGIN_SRC python :results output org drawer :session sesson2
55 # cursor here, type C-c C-v C-z and get readonly repl
#+END_SRC
#+RESULTS:
:RESULTS:
55
:END:
Launch emacs: emacs -Q -l init.el test.org
the first block in the first file works as expected. When you add the hook function though, the block in the second file gives a read-only repl. I don't know why.