This is an archive of the discontinued LLVM Phabricator instance.

[emacs] Add regexps for defuns
ClosedPublic

Authored by luke on Aug 17 2023, 9:18 AM.

Details

Summary

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.

Diff Detail

Unit TestsFailed

Event Timeline

luke created this revision.Aug 17 2023, 9:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2023, 9:18 AM
luke requested review of this revision.Aug 17 2023, 9:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2023, 9:18 AM
goldstein.w.n added inline comments.Aug 17 2023, 11:56 AM
llvm/utils/emacs/llvm-mode.el
102

Slightly buggy.
Fails on something like:

define i1 @foo() {
  ret i1 true
}

You need .+ -> .* within the parens. I.e no variables is acceptable.

111

Likewise here.

luke updated this revision to Diff 551453.Aug 18 2023, 3:22 AM

Handle functions with no arguments and trailing attributes (e.g. nounwind)

luke marked 2 inline comments as done.Aug 18 2023, 3:23 AM
luke added inline comments.
llvm/utils/emacs/llvm-mode.el
111

Whoops. Also found we need to handle trailing attributes like nounwind etc., since defun-prompt-regexp needs to match right up to the first {

goldstein.w.n added inline comments.Aug 18 2023, 10:52 PM
llvm/utils/emacs/llvm-mode.el
111

Does this still need to be fixed. Don't see any codes for matching {.

luke marked 2 inline comments as done.Aug 19 2023, 11:30 AM
luke added inline comments.
llvm/utils/emacs/llvm-mode.el
111

This is fixed, IIUC emacs automatically looks between top-level { braces for defuns, but by default they have to be in column 0. So defun-prompt-regexp skips over those characters so that { is then the first character, e.g. see the definition for bash: https://github.com/emacs-mirror/emacs/blob/7b30e11b2ac5cd360db7ee8b6aed07bd918b93a2/lisp/progmodes/sh-script.el#L1531C1-L1537

This revision is now accepted and ready to land.Aug 19 2023, 12:50 PM
This revision was landed with ongoing or failed builds.Aug 21 2023, 2:44 AM
This revision was automatically updated to reflect the committed changes.
luke marked an inline comment as done.