From: Eshel Yaron Date: Tue, 22 Apr 2025 21:18:13 +0000 (+0200) Subject: Better support for Elisp icon names. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=24ec32f67fa2d1c438a4c71dd0a51bfb5654848a;p=emacs.git Better support for Elisp icon names. --- diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index 13c58482697..6d7dede9d8b 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -82,6 +82,9 @@ Please send improvements and fixes to the maintainer." (defvar find-symbol-type-regexp (concat "^\\s-*(scope-define-symbol-type" find-function-space-re "%s\\(\\s-\\|$\\)")) +(defvar find-icon-regexp + (concat "^\\s-*(define-icon" find-function-space-re "%s\\(\\s-\\|$\\)")) + (defvar find-widget-regexp (concat "^\\s-*(define-widget" find-function-space-re "%s\\(\\s-\\|$\\)")) @@ -144,6 +147,7 @@ should insert the feature name." (ert-deftest . find-ert-deftest-regexp) (define-widget . find-widget-regexp) (define-error . find-error-regexp) + (define-icon . find-icon-regexp) (define-symbol-type . find-symbol-type-regexp)) "Alist mapping definition types into regexp variables. Each regexp variable's value should actually be a format string diff --git a/lisp/emacs-lisp/icons.el b/lisp/emacs-lisp/icons.el index 3ad91aea6f7..d6679a59311 100644 --- a/lisp/emacs-lisp/icons.el +++ b/lisp/emacs-lisp/icons.el @@ -83,6 +83,7 @@ the icon is used as a button and you click it." (defun icons--register (name parent spec doc keywords) (put name 'icon--properties (list parent spec doc keywords)) + (add-to-list 'current-load-list `(define-icon . ,name)) (custom-add-to-group (or (plist-get keywords :group) (custom-current-group)) @@ -245,7 +246,7 @@ present if the icon is represented by an image." (defun describe-icon (icon) "Pop to a buffer to describe ICON." (interactive - (list (intern (completing-read "Describe icon: " obarray 'iconp t)))) + (list (intern (completing-read "Describe icon: " obarray #'iconp t)))) (let ((icon (if (stringp icon) (intern icon) icon)) (help-buffer-under-preparation t)) (help-setup-xref (list #'describe-icon icon) diff --git a/lisp/emacs-lisp/scope.el b/lisp/emacs-lisp/scope.el index b7d488aa5c3..0b3d64632ad 100644 --- a/lisp/emacs-lisp/scope.el +++ b/lisp/emacs-lisp/scope.el @@ -321,6 +321,20 @@ :help (lambda (beg _end def) (if (equal beg def) "Block definition" "Block"))) +(scope-define-symbol-type icon () + :doc "Icon names." + :face 'font-lock-type-face + :help (constantly "Icon") + :completion (constantly (lambda (sym) (get sym 'icon--properties))) + :namespace 'icon) + +(scope-define-symbol-type deficon () + :doc "Icon definitions." + :face 'font-lock-type-face + :help (constantly "Icon definition") + :imenu "Icon" + :namespace 'icon) + (defvar scope-counter nil) (defvar scope-local-functions nil) @@ -1658,9 +1672,21 @@ a (possibly empty) list of safe macros.") (scope-define-function-analyzer scope-report (type &rest _) (when-let ((q (scope--unqoute type))) (scope-report-s q 'symbol-type))) -(scope-define-function-analyzer scope-report-s (_sym type) +(scope-define-function-analyzer scope-report-s (&optional _sym type) (when-let ((q (scope--unqoute type))) (scope-report-s q 'symbol-type))) +(scope-define-function-analyzer icons--register (&optional name parent _spec _doc kws) + (when-let ((q (scope--unqoute name))) (scope-report-s q 'deficon)) + (when-let ((q (scope--unqoute parent))) (scope-report-s q 'icon)) + (when-let ((q (scope--unqoute kws))) + (while-let ((kw (car-safe q)) + (bkw (scope-sym-bare kw)) + ((keywordp bkw))) + (scope-report-s kw 'constant) + (case bkw + (:group (scope-report-s (cadr q) 'group))) + (setq q (cddr q))))) + (scope-define-macro-analyzer define-globalized-minor-mode (l global mode turn-on &rest body) (scope-report-s mode 'function) (scope-report-s turn-on 'function) diff --git a/lisp/loadhist.el b/lisp/loadhist.el index ff531403c6c..3e18eb1da66 100644 --- a/lisp/loadhist.el +++ b/lisp/loadhist.el @@ -244,6 +244,9 @@ unloading." (put name 'scope-parent-types nil) (put name 'scope-type-properties nil))) +(cl-defmethod loadhist-unload-element ((x (head define-icon))) + (let ((name (cdr x))) (put name 'icon--properties nil))) + ;;;###autoload (defun unload-feature (feature &optional force) "Unload the library that provided FEATURE. diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index cc780138e1b..8965e5d6587 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1115,6 +1115,7 @@ confidence." (feature '(feature)) (widget-type '(widget-type)) (condition '(condition)) + (icon '(deficon icon)) (variable '(defvar variable constant)) (symbol-type '(symbol-type symbol-type-definition)) (function '(defun function macro special-form major-mode))))) @@ -1190,6 +1191,7 @@ confidence." ('face '(defface)) ('feature '(feature)) ('condition '(define-error)) + ('icon '(define-icon)) ('symbol-type '(define-symbol-type)) ('widget-type '(define-widget))))) (cl-loop for d in definitions @@ -1243,6 +1245,10 @@ confidence." (when-let ((file (find-lisp-object-file-name symbol 'define-error))) (push (elisp--xref-make-xref 'define-error symbol file) xrefs))) + (when (get symbol 'icon--properties) + (when-let ((file (find-lisp-object-file-name symbol 'define-icon))) + (push (elisp--xref-make-xref 'define-icon symbol file) xrefs))) + (when (scope-symbol-type-p symbol) (when-let ((file (find-lisp-object-file-name symbol 'define-symbol-type))) (push (elisp--xref-make-xref 'define-symbol-type symbol file) xrefs))) @@ -2688,6 +2694,7 @@ of TARGET." (if (time-less-p (or (car cached) 0) modtime) (puthash file (cons modtime (with-work-buffer + (setq lexical-binding t) (insert-file-contents file) (elisp-symbols-index-1 file))) elisp-symbols-index-cache)