Skip to content
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

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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).

### 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