]> git.eshelyaron.com Git - emacs.git/commitdiff
elisp-mode.el: Better support for charsets
authorEshel Yaron <me@eshelyaron.com>
Wed, 11 Jun 2025 12:07:58 +0000 (14:07 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 11 Jun 2025 12:07:58 +0000 (14:07 +0200)
doc/lispref/minibuf.texi
doc/lispref/nonascii.texi
lisp/emacs-lisp/find-func.el
lisp/emacs-lisp/scope.el
lisp/international/mule-diag.el
lisp/international/mule.el
lisp/loadhist.el
lisp/progmodes/elisp-mode.el
src/callint.c
src/coding.c

index 36c1bf46adbcbbd9217b04979de2dad83c3aabec..98a19c19b9e8f740f76a952280f7f3bbbfdafe6f 100644 (file)
@@ -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
index cc1f9d6140139cfbdb3d75aea83880a7584b33fa..e2de41d9d8f2d6ab149bbc3833f8bcf93fb1ad2c 100644 (file)
@@ -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
index f451e9b14aaeac97c770cce722410478cf5cc410..40e294e46de52274038e59c45623a98a060b342a 100644 (file)
@@ -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
index 9efd7cc5e0f37bc255a483b86ecb18cc45d495b3..78aee4faed09bb000c51d21a200938052fe032a8 100644 (file)
   :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)))
index e672d422ff6b199aa66365a8871217dd079f6a43..7107b2b4586df0d5bd75cd7291bb74714cf965a3 100644 (file)
@@ -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)
index b556ef906bb175f98665a393e713d63a93b9c308..e5c8c8bb64cfaa73d2c26e70f036487459c5fe60 100644 (file)
@@ -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
index 2f3c55111161f1cc75ea89b6e105ebcc31a6f734..bca082bf4f83594464c5d38aa9851f9491fb4434 100644 (file)
@@ -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.
index 5a669ee7511bcc6c4e88210bcc606907a18fd38c..c4ab016303e81b8bd91a6a222bc3b27df703358c 100644 (file)
@@ -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)))
index a068effd3449800370b90d9f6b9395af2523ac3b..bd72149f043e04ff504d4f7de1132899be3de534 100644 (file)
@@ -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;
index a923b6bd82d1f21779ead40fd9871a9ea87fa217..fd0977b7f1a2bbd06d5cac5151e0576f2f5331a6 100644 (file)
@@ -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);