[llvm] b0af89c - [emacs] Add regexps for defuns

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 02:43:47 PDT 2023


Author: Luke Lau
Date: 2023-08-21T10:43:41+01:00
New Revision: b0af89cbdad445e735a3506029dbb61c75ecaab2

URL: https://github.com/llvm/llvm-project/commit/b0af89cbdad445e735a3506029dbb61c75ecaab2
DIFF: https://github.com/llvm/llvm-project/commit/b0af89cbdad445e735a3506029dbb61c75ecaab2.diff

LOG: [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

Added: 
    

Modified: 
    llvm/utils/emacs/llvm-mode.el

Removed: 
    


################################################################################
diff  --git a/llvm/utils/emacs/llvm-mode.el b/llvm/utils/emacs/llvm-mode.el
index bb0804ad5fa378..e37cc693a1940a 100644
--- a/llvm/utils/emacs/llvm-mode.el
+++ b/llvm/utils/emacs/llvm-mode.el
@@ -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]+ at .+(.*).+")
+  (setq-local add-log-current-defun-function #'llvm-current-defun-name)
   (setq-local comment-start ";"))
 
 ;; Associate .ll files with llvm-mode


        


More information about the llvm-commits mailing list