Skip to content

Set add-log-current-defun-function #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of the entire function seems off (it's 2 spaces too indented), so you might want to use indent-region on it.

I'd also suggest expanding the docstring to mention this function is meant to be used 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."
(add-to-list 'imenu-generic-expression '(nil clojure-match-next-def 0))
Expand Down Expand Up @@ -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 ()
Expand Down