Set add-log-current-defun-function #629
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A number of emacs' programming modes1 set the variable
add-log-current-defun-function
to a function which returns the current defun/function/variable/etc name, e.g. inlisp/emacs-lisp/lisp-mode.el
:(setq-local add-log-current-defun-function #'lisp-current-defun-name)
(https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/lisp-mode.el#n683).This variable is used by which-function-mode to get the name of the current function (otherwise it falls back to some logic based on imenu). It is also used by easy-kill, which then allows the copying of the current defun name (
M-w D
). The latter is the reason I wanted this, as it doesn't work without setting the variable. I haven't discovered anything else that uses it.The function I have added (
clojure-current-defun-name
) is a copy of lisp-current-defun-name fromlisp-mode.el
(https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/lisp-mode.el#n730), with the small addition of the code to skip metadata (indicated the "Skip metadata" comment), and a tweak to the comments.I have been using this for a few weeks without issue. It works with def, defn, defn-, defmacro and ns fine.
The convention seems to be to call the function
foo-current-defun-name
, even when the language doesn't usedefun
(e.g.perl-current-defun-name
,sh-current-defun-name
,html-current-defun-name
), so I have stuck with that.1 A quick search in
lisp/
in the emacs source turned up these: autoconf, idlwave, cfengine, fortran, cperl-mode, scheme, m4-mode, make-mode, perl-mode, sh-script, tcl, cc-mode, python, octave, ruby-mode, f90, texinfo, sgml-mode, css-mode, tex-mode, diff-mode, org-mode.Before submitting a PR mark the checkboxes for the items you've done (if you
think a checkbox does not apply, then leave it unchecked):
M-x checkdoc
and fixed any warnings in the code you've written.Thanks!