Skip to content

Commit

Permalink
Set add-log-current-defun-function (clojure-emacs#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
deejayem authored Aug 24, 2022
1 parent 0be365a commit 905abd0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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).

### Bugs fixed

* [#581](https://github.com/clojure-emacs/clojure-mode/issues/581): Fix font locking not working for keywords starting with a number
Expand Down
32 changes: 32 additions & 0 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,37 @@ 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.
`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."
(add-to-list 'imenu-generic-expression '(nil clojure-match-next-def 0))
Expand Down Expand Up @@ -552,6 +583,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

0 comments on commit 905abd0

Please sign in to comment.