elisp--highlight-function-argument: Use temporary buffer

* lisp/progmodes/elisp-mode.el
(elisp--highlight-function-argument): Insert 'args' into
temporary buffer to prepare for better handling of usage
arguments (bug#8432).  Move point after the first opening
parenthesis of the arguments string.  In the loop, let `origin'
track the point.  No functional change.
This commit is contained in:
Vili Aapro 2026-02-01 16:21:57 +02:00 committed by Sean Whitton
parent 858cebd6c5
commit 7d2303aef8

View file

@ -2443,32 +2443,36 @@ ARGS is the argument list of function SYM."
start (match-beginning 0)
end (match-end 0)))))))
;; Handle now positional arguments.
(while (and index (>= index 1))
(if (string-match "[^ ()]+" args end)
(progn
(setq start (match-beginning 0)
end (match-end 0))
(let ((argument (match-string 0 args)))
(cond ((string= argument "&rest")
;; All the rest arguments are the same.
(setq index 1))
((string= argument "&optional")) ; Skip.
((string= argument "&allow-other-keys")) ; Skip.
;; Back to index 0 in ARG1 ARG2 ARG2 ARG3 etc...
;; like in `setq'.
((or (and (string-match-p "\\.\\.\\.\\'" argument)
(string= argument (car (last args-lst))))
(and (string-match-p "\\.\\.\\.\\'"
(substring args 1 (1- (length args))))
(= (length (remove "..." args-lst)) 2)
(> index 1) (oddp index)))
(setq index 0))
(t
(setq index (1- index))))))
(setq end (length args)
start (1- end)
argument-face 'font-lock-warning-face
index 0)))
(with-temp-buffer
(insert args)
(goto-char (1+ (point-min)))
(while (and index (>= index 1))
(let ((origin (point)))
(if (string-match "[^ ()]+" args end)
(progn
(setq start (match-beginning 0)
end (match-end 0))
(let ((argument (match-string 0 args)))
(cond ((string= argument "&rest")
;; All the rest arguments are the same.
(setq index 1))
((string= argument "&optional")) ; Skip.
((string= argument "&allow-other-keys")) ; Skip.
;; Back to index 0 in ARG1 ARG2 ARG2 ARG3 etc...
;; like in `setq'.
((or (and (string-match-p "\\.\\.\\.\\'" argument)
(string= argument (car (last args-lst))))
(and (string-match-p "\\.\\.\\.\\'"
(substring args 1 (1- (length args))))
(= (length (remove "..." args-lst)) 2)
(> index 1) (oddp index)))
(setq index 0))
(t
(setq index (1- index))))))
(setq end (length args)
start (1- end)
argument-face 'font-lock-warning-face
index 0)))))
(let ((doc args))
(when start
(setq doc (copy-sequence args))