branch: externals/org
commit ecb62e2e317b1a4b5b8a6c0f111ed7ef18413040
Author: Stefan Monnier <[email protected]>
Commit: Ihor Radchenko <[email protected]>
org-babel-shell-initialize: Refactor
* lisp/ob-shell.el (org-babel-shell-initialize): Refactor avoiding
`eval' runtime calls and assigning 'definition-name function symbol
property to assist Emacs help system with finding the definition.
Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60568#71
> One of the discussed features was displaying function source code right
> in *Help* buffers. This feature usefulness have been objected at that
> time, on the grounds that showing function code may be too long and
> cause large *Help* buffers.
FWIW, I find myself regularly jumping to `M-x ielm` to look at the
`symbol-function`, so I would actually appreciate a button in the *Help*
buffer to display the actual value in the `symbol-function` slot.
This would also bring `describe-function` a bit closer to
`describe-variable`, which I think is good.
> 1. emacs -Q
> 2. M-: (require 'ob-shell)
> 3. <F1> f org-babel-execute:sh <RET>
> 4. Click on the source code link in *Help* buffer
> 5. Observe point jumping to (point-min) with no obvious way to find the
> function definition.
We have `definition-name` for that.
I.e. `org-babel-shell-initialize` should arguably do
(put 'org-babel-execute:sh 'definition-name 'org-babel-shell-initialize)
so that step 4 above jumps to `org-babel-shell-initialize`.
The patch below does that, along with saving some kittens.
Stefan
---
lisp/ob-shell.el | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 7b2d5192c7..9e7b45a891 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -75,20 +75,25 @@ This function has to be called whenever
`org-babel-shell-names'
is modified outside the Customize interface."
(interactive)
(dolist (name org-babel-shell-names)
- (eval `(defun ,(intern (concat "org-babel-execute:" name))
- (body params)
- ,(format "Execute a block of %s commands with Babel." name)
- (let ((shell-file-name ,name)
- (org-babel-prompt-command
- (or (cdr (assoc ,name org-babel-shell-set-prompt-commands))
- (alist-get t org-babel-shell-set-prompt-commands))))
- (org-babel-execute:shell body params))))
- (eval `(defalias ',(intern (concat "org-babel-variable-assignments:" name))
- 'org-babel-variable-assignments:shell
- ,(format "Return list of %s statements assigning to the block's \
+ (let ((fname (intern (concat "org-babel-execute:" name))))
+ (defalias fname
+ (lambda (body params)
+ (:documentation
+ (format "Execute a block of %s commands with Babel." name))
+ (let ((shell-file-name name)
+ (org-babel-prompt-command
+ (or (cdr (assoc name org-babel-shell-set-prompt-commands))
+ (alist-get t org-babel-shell-set-prompt-commands))))
+ (org-babel-execute:shell body params))))
+ (put fname 'definition-name 'org-babel-shell-initialize))
+ (defalias (intern (concat "org-babel-variable-assignments:" name))
+ #'org-babel-variable-assignments:shell
+ (format "Return list of %s statements assigning to the block's \
variables."
- name)))
- (eval `(defvar ,(intern (concat "org-babel-default-header-args:" name))
'()))))
+ name))
+ (funcall (if (fboundp 'defvar-1) #'defvar-1 #'set) ;Emacs-29
+ (intern (concat "org-babel-default-header-args:" name))
+ nil)))
(defcustom org-babel-shell-names
'("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh")