Skip to content

Commit

Permalink
[emacs] Add regexps for defuns
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lukel97 authored and razmser committed Oct 6, 2023
1 parent b449229 commit 81ecfd8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions llvm/utils/emacs/llvm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,21 @@
`(,(regexp-opt '("uselistorder" "uselistorder_bb") 'symbols) . font-lock-keyword-face))
"Syntax highlighting for LLVM.")

(defun llvm-current-defun-name ()
"The `add-log-current-defun' function in LLVM mode."
(save-excursion
(end-of-line)
(if (re-search-backward "^[ \t]*define[ \t]+.+[ \t]+@\\(.+\\)(.*)" nil t)
(match-string-no-properties 1))))

;;;###autoload
(define-derived-mode llvm-mode prog-mode "LLVM"
"Major mode for editing LLVM source files.
\\{llvm-mode-map}
Runs `llvm-mode-hook' on startup."
(setq font-lock-defaults `(llvm-font-lock-keywords))
(setq-local defun-prompt-regexp "^[ \t]*define[ \t]+.+[ \t]+@.+(.*).+")
(setq-local add-log-current-defun-function #'llvm-current-defun-name)
(setq-local comment-start ";"))

;; Associate .ll files with llvm-mode
Expand Down

0 comments on commit 81ecfd8

Please sign in to comment.