From 76673704de81cfa4291f40ea0f6a9c02472789b5 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 11 Jun 2025 14:07:58 +0200 Subject: [PATCH] elisp-mode.el: Better support for charsets --- doc/lispref/minibuf.texi | 6 ++--- doc/lispref/nonascii.texi | 7 ------ lisp/emacs-lisp/find-func.el | 5 ++-- lisp/emacs-lisp/scope.el | 44 +++++++++++++++++++++++++++++++++ lisp/international/mule-diag.el | 5 ++-- lisp/international/mule.el | 2 +- lisp/loadhist.el | 4 +++ lisp/progmodes/elisp-mode.el | 9 ++++--- src/callint.c | 3 +-- src/coding.c | 17 ------------- 10 files changed, 65 insertions(+), 37 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 36c1bf46adb..98a19c19b9e 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -1552,9 +1552,9 @@ foreground color is changed to be the color of the candidate, otherwise the background is changed to the candidate's color. @end deffn - See also the functions @code{read-coding-system} and -@code{read-non-nil-coding-system}, in @ref{User-Chosen Coding Systems}, -and @code{read-input-method-name}, in @ref{Input Methods}. + See also the functions @code{read-coding-system} in @ref{User-Chosen +Coding Systems}, and @code{read-input-method-name}, in @ref{Input +Methods}. @node Reading File Names @subsection Reading File Names diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi index cc1f9d61401..e2de41d9d8f 100644 --- a/doc/lispref/nonascii.texi +++ b/doc/lispref/nonascii.texi @@ -1547,13 +1547,6 @@ the user enters null input, @var{default} specifies which coding system to return. It should be a symbol or a string. @end defun -@defun read-non-nil-coding-system prompt -This function reads a coding system using the minibuffer, prompting with -string @var{prompt}, and returns the coding system name as a symbol. If -the user tries to enter null input, it asks the user to try again. -@xref{Coding Systems}. -@end defun - @node Default Coding Systems @subsection Default Coding Systems @cindex default coding system diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index f451e9b14aa..40e294e46de 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -88,8 +88,8 @@ Please send improvements and fixes to the maintainer." (defvar find-coding-system-regexp (concat "^\\s-*(define-coding-system" find-function-space-re "%s\\(\\s-\\|$\\)")) -(defvar find-widget-regexp - (concat "^\\s-*(define-widget" find-function-space-re "%s\\(\\s-\\|$\\)")) +(defvar find-charset-regexp + (concat "^\\s-*(define-charset" find-function-space-re "%s\\(\\s-\\|$\\)")) (defcustom find-face-regexp (concat"^\\s-*(defface" find-function-space-re "%s\\(\\s-\\|$\\)") @@ -152,6 +152,7 @@ should insert the feature name." (define-error . find-error-regexp) (define-icon . find-icon-regexp) (define-coding-system . find-coding-system-regexp) + (define-charset . find-charset-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/scope.el b/lisp/emacs-lisp/scope.el index 9efd7cc5e0f..78aee4faed0 100644 --- a/lisp/emacs-lisp/scope.el +++ b/lisp/emacs-lisp/scope.el @@ -382,6 +382,26 @@ :imenu "Coding system" :namespace 'coding) +(scope-define-symbol-type charset () + :doc "Charset names." + :face 'font-lock-type-face + :help (lambda (beg end _def) + (if-let ((sym (intern (buffer-substring-no-properties beg end)))) + (lambda (&rest _) + (if-let ((doc (charset-description sym))) + (format "Charset `%S'.\n\n%s" sym doc) + "Charset")) + "Charset")) + :completion (constantly #'charsetp) + :namespace 'charset) + +(scope-define-symbol-type defcharset () + :doc "Charset definitions." + :face 'font-lock-type-face + :help (constantly "Charset definition") + :imenu "Charset" + :namespace 'charset) + (defvar scope-counter nil) (defvar scope-local-functions nil) @@ -1562,6 +1582,30 @@ a (possibly empty) list of safe macros.") (when-let ((q (scope--unqoute (cadr props)))) (scope-report-s q 'defun)))) (setq props (cddr props)))) +(scope-define-function-analyzer define-charset + (&optional name _docstring &rest _props) + (when-let ((quoted (scope--unqoute name))) (scope-report-s quoted 'defcharset))) + +(scope-define-function-analyzer define-charset-alias + (&optional alias charset) + (when-let ((quoted (scope--unqoute alias))) (scope-report-s quoted 'defcharset)) + (when-let ((quoted (scope--unqoute charset))) (scope-report-s quoted 'charset))) + +(scope-define-function-analyzer charset-chars + (&optional charset &rest _) + (when-let ((quoted (scope--unqoute charset))) (scope-report-s quoted 'charset))) + +(dolist (sym '(charset-description charset-info charset-iso-final-char + charset-long-name charset-plist + charset-short-name + get-charset-property put-charset-property + list-charset-chars + set-charset-plist + set-charset-priority + unify-charset + locale-charset-to-coding-system)) + (put sym 'scope-analyzer #'scope--analyze-charset-chars)) + (scope-define-function-analyzer define-coding-system (&optional name _docstring &rest _props) (when-let ((quoted (scope--unqoute name))) (scope-report-s quoted 'defcoding))) diff --git a/lisp/international/mule-diag.el b/lisp/international/mule-diag.el index e672d422ff6..7107b2b4586 100644 --- a/lisp/international/mule-diag.el +++ b/lisp/international/mule-diag.el @@ -210,8 +210,9 @@ DEFAULT-VALUE, if non-nil, is the default value. INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially. See the documentation of the function `completing-read' for the detailed meanings of these arguments." - (let* ((table (mapcar (compf list symbol-name) charset-list)) - (charset (completing-read prompt table + (let* ((charset (completing-read prompt + (completion-table-with-metadata + charset-list '((category . charset))) nil t initial-input 'charset-history default-value))) (if (> (length charset) 0) diff --git a/lisp/international/mule.el b/lisp/international/mule.el index b556ef906bb..e5c8c8bb64c 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el @@ -285,7 +285,7 @@ attribute." (plist-put props :long-name (plist-get props :short-name))) (plist-put props :base name) (setcdr (assq :plist attrs) props) - + (add-to-list 'current-load-list `(define-charset . ,name)) (apply 'define-charset-internal name (mapcar 'cdr attrs)))) (defvar hack-read-symbol-shorthands-function nil diff --git a/lisp/loadhist.el b/lisp/loadhist.el index 2f3c5511116..bca082bf4f8 100644 --- a/lisp/loadhist.el +++ b/lisp/loadhist.el @@ -251,6 +251,10 @@ unloading." ;; FIXME: Implement it. nil) +(cl-defmethod loadhist-unload-element ((_x (head define-charset))) + ;; FIXME: Implement it. + 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 5a669ee7511..c4ab016303e 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1164,6 +1164,7 @@ confidence." (condition '(condition)) (icon '(deficon icon)) (coding '(defcoding coding)) + (charset '(defcharset charset)) (variable '(defvar variable constant)) (symbol-type '(symbol-type symbol-type-definition)) (function '(defun function macro special-form major-mode))))) @@ -1242,6 +1243,7 @@ confidence." ('icon '(define-icon)) ('symbol-type '(define-symbol-type)) ('coding '(define-coding-system)) + ('charset '(define-charset)) ('oclosure '(oclosure)) ('widget-type '(define-widget))))) (cl-loop for d in definitions @@ -1264,9 +1266,6 @@ confidence." ;; FIXME: advised function; list of advice functions ;; FIXME: aliased variable - ;; Coding system symbols do not appear in ‘load-history’, - ;; so we can’t get a location for them. - (when (and (symbolp symbol) (symbol-function symbol) (symbolp (symbol-function symbol))) @@ -1303,6 +1302,10 @@ confidence." (when-let ((file (find-lisp-object-file-name symbol 'define-coding-system))) (push (elisp--xref-make-xref 'define-coding-system symbol file) xrefs))) + (when (charsetp symbol) + (when-let ((file (find-lisp-object-file-name symbol 'define-charset))) + (push (elisp--xref-make-xref 'define-charset 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))) diff --git a/src/callint.c b/src/callint.c index a068effd344..bd72149f043 100644 --- a/src/callint.c +++ b/src/callint.c @@ -697,8 +697,7 @@ See also `interactive'. */) } else { - args[i] - = Fread_non_nil_coding_system (callint_message); + args[i] = Fread_coding_system (callint_message, Qnil); visargs[i] = last_minibuf_string; } break; diff --git a/src/coding.c b/src/coding.c index a923b6bd82d..fd0977b7f1a 100644 --- a/src/coding.c +++ b/src/coding.c @@ -8629,22 +8629,6 @@ about coding-system objects. */) return Qt; } -DEFUN ("read-non-nil-coding-system", Fread_non_nil_coding_system, - Sread_non_nil_coding_system, 1, 1, 0, - doc: /* Read a coding system from the minibuffer, prompting with string PROMPT. -Return the symbol of the coding-system. */) - (Lisp_Object prompt) -{ - Lisp_Object val; - do - { - val = Fcompleting_read (prompt, Vcoding_system_alist, Qnil, - Qt, Qnil, Qcoding_system_history, Qnil, Qnil); - } - while (SCHARS (val) == 0); - return (Fintern (val, Qnil)); -} - DEFUN ("read-coding-system", Fread_coding_system, Sread_coding_system, 1, 2, 0, doc: /* Read a coding system from the minibuffer, prompting with string PROMPT. If the user enters null input, return second argument DEFAULT-CODING-SYSTEM. @@ -11922,7 +11906,6 @@ syms_of_coding (void) defsubr (&Scoding_system_p); defsubr (&Sread_coding_system); - defsubr (&Sread_non_nil_coding_system); defsubr (&Scheck_coding_system); defsubr (&Sdetect_coding_region); defsubr (&Sdetect_coding_string); -- 2.39.5