From c0399a32f90844c36277a4b354e42a4eefa89f07 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Wed, 24 Aug 2022 16:43:00 +0100 Subject: [PATCH 1/3] Set add-log-current-defun-function --- clojure-mode.el | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/clojure-mode.el b/clojure-mode.el index 5b6c7f79..f5759794 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -524,6 +524,35 @@ replacement for `cljr-expand-let`." #'clojure-space-for-delimiter-p) (advice-add 'paredit-convolute-sexp :after #'clojure--replace-let-bindings-and-indent))) +(defun clojure-current-defun-name () + "Return the name of the defun at point, or nil." + (save-excursion + (let ((location (point))) + ;; If we are now precisely at the beginning of a defun, make sure + ;; beginning-of-defun finds that one rather than the previous one. + (or (eobp) (forward-char 1)) + (beginning-of-defun) + ;; Make sure we are really inside the defun found, not after it. + (when (and (looking-at "\\s(") + (progn (end-of-defun) + (< location (point))) + (progn (forward-sexp -1) + (>= location (point)))) + (if (looking-at "\\s(") + (forward-char 1)) + ;; Skip the defining construct name, e.g. "defn" or "def". + (forward-sexp 1) + ;; The second element is usually a symbol being defined. If it + ;; is not, use the first symbol in it. + (skip-chars-forward " \t\n'(") + ;; Skip metadata + (while (looking-at "\\^") + (forward-sexp 1) + (skip-chars-forward " \t\n'(")) + (buffer-substring-no-properties (point) + (progn (forward-sexp 1) + (point))))))) + (defun clojure-mode-variables () "Set up initial buffer-local variables for Clojure mode." (add-to-list 'imenu-generic-expression '(nil clojure-match-next-def 0)) @@ -552,6 +581,7 @@ replacement for `cljr-expand-let`." (setq-local parse-sexp-ignore-comments t) (setq-local prettify-symbols-alist clojure--prettify-symbols-alist) (setq-local open-paren-in-column-0-is-defun-start nil) + (setq-local add-log-current-defun-function #'clojure-current-defun-name) (setq-local beginning-of-defun-function #'clojure-beginning-of-defun-function)) (defsubst clojure-in-docstring-p () From b933a1e66e1cb8ed5c3674962d63822cfb743c38 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Wed, 24 Aug 2022 17:32:04 +0100 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8f864bb..8b6a7bdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Changes + +* [#629](https://github.com/clojure-emacs/clojure-mode/pull/629): Set `add-log-current-defun-function` to new function `clojure-current-defun-name` (this is used by which-function-mode and easy-kill). + ## 5.15.1 (2022-07-30) ### Bugs fixed From 3f70f463d8df7d674629c2a2276373427efbca2c Mon Sep 17 00:00:00 2001 From: David Morgan Date: Wed, 24 Aug 2022 18:20:31 +0100 Subject: [PATCH 3/3] Fix indentation and extend docstring --- clojure-mode.el | 56 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/clojure-mode.el b/clojure-mode.el index f5759794..b3c20530 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -525,33 +525,35 @@ replacement for `cljr-expand-let`." (advice-add 'paredit-convolute-sexp :after #'clojure--replace-let-bindings-and-indent))) (defun clojure-current-defun-name () - "Return the name of the defun at point, or nil." - (save-excursion - (let ((location (point))) - ;; If we are now precisely at the beginning of a defun, make sure - ;; beginning-of-defun finds that one rather than the previous one. - (or (eobp) (forward-char 1)) - (beginning-of-defun) - ;; Make sure we are really inside the defun found, not after it. - (when (and (looking-at "\\s(") - (progn (end-of-defun) - (< location (point))) - (progn (forward-sexp -1) - (>= location (point)))) - (if (looking-at "\\s(") - (forward-char 1)) - ;; Skip the defining construct name, e.g. "defn" or "def". - (forward-sexp 1) - ;; The second element is usually a symbol being defined. If it - ;; is not, use the first symbol in it. - (skip-chars-forward " \t\n'(") - ;; Skip metadata - (while (looking-at "\\^") - (forward-sexp 1) - (skip-chars-forward " \t\n'(")) - (buffer-substring-no-properties (point) - (progn (forward-sexp 1) - (point))))))) + "Return the name of the defun at point, or nil. + +`add-log-current-defun-function' is set to this, for use by `which-func'." + (save-excursion + (let ((location (point))) + ;; If we are now precisely at the beginning of a defun, make sure + ;; beginning-of-defun finds that one rather than the previous one. + (or (eobp) (forward-char 1)) + (beginning-of-defun) + ;; Make sure we are really inside the defun found, not after it. + (when (and (looking-at "\\s(") + (progn (end-of-defun) + (< location (point))) + (progn (forward-sexp -1) + (>= location (point)))) + (if (looking-at "\\s(") + (forward-char 1)) + ;; Skip the defining construct name, e.g. "defn" or "def". + (forward-sexp 1) + ;; The second element is usually a symbol being defined. If it + ;; is not, use the first symbol in it. + (skip-chars-forward " \t\n'(") + ;; Skip metadata + (while (looking-at "\\^") + (forward-sexp 1) + (skip-chars-forward " \t\n'(")) + (buffer-substring-no-properties (point) + (progn (forward-sexp 1) + (point))))))) (defun clojure-mode-variables () "Set up initial buffer-local variables for Clojure mode."