Skip to content

Commit b0af89c

Browse files
committed
[emacs] Add regexps for defuns
Previously `M-x mark-defun` and friends wouldn't work properly, and would highlight something at the top of the buffer. This adds a regexp for top-level functions so the defun functions should work as expected, and also adds a regexp for extracting their name so which-function-mode should work now too. Reviewed By: goldstein.w.n Differential Revision: https://reviews.llvm.org/D158196
1 parent b16a758 commit b0af89c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

llvm/utils/emacs/llvm-mode.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,21 @@
9595
`(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))
9696
"Syntax highlighting for LLVM.")
9797

98+
(defun llvm-current-defun-name ()
99+
"The `add-log-current-defun' function in LLVM mode."
100+
(save-excursion
101+
(end-of-line)
102+
(if (re-search-backward "^[ \t]*define[ \t]+.+[ \t]+@\\(.+\\)(.*)" nil t)
103+
(match-string-no-properties 1))))
104+
98105
;;;###autoload
99106
(define-derived-mode llvm-mode prog-mode "LLVM"
100107
"Major mode for editing LLVM source files.
101108
\\{llvm-mode-map}
102109
Runs `llvm-mode-hook' on startup."
103110
(setq font-lock-defaults `(llvm-font-lock-keywords))
111+
(setq-local defun-prompt-regexp "^[ \t]*define[ \t]+.+[ \t]+@.+(.*).+")
112+
(setq-local add-log-current-defun-function #'llvm-current-defun-name)
104113
(setq-local comment-start ";"))
105114

106115
;; Associate .ll files with llvm-mode

0 commit comments

Comments
 (0)