emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 162/299: Fix a bug where customizing LaTeX-math-list had no effec


From: Stefan Monnier
Subject: [elpa] 162/299: Fix a bug where customizing LaTeX-math-list had no effect until restarting emacs.
Date: Sun, 02 Nov 2014 03:11:09 +0000

monnier pushed a commit to branch externals/auctex
in repository elpa.

commit c83a72bc383656208ee8bd0830cfe86dda02ce46
Author: Tassilo Horn <address@hidden>
Date:   Wed Jul 31 09:18:59 2013 +0200

    Fix a bug where customizing LaTeX-math-list had no effect until restarting
    emacs.
    
    * latex.el (LaTeX-math-initialize): Refactor top-level code into
    function.
    (LaTeX-math-list): Call `LaTeX-math-initialize' when setting the
    value in order to update the key bindings.
    Also shuffle around several definitions in order to get a
    declaration-before-use order.
---
 ChangeLog |    9 ++
 latex.el  |  258 +++++++++++++++++++++++++++++++------------------------------
 2 files changed, 140 insertions(+), 127 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fbf2244..887714c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-07-31  Tassilo Horn  <address@hidden>
+
+       * latex.el (LaTeX-math-initialize): Refactor top-level code into
+       function.
+       (LaTeX-math-list): Call `LaTeX-math-initialize' when setting the
+       value in order to update the key bindings.
+       Also shuffle around several definitions in order to get a
+       declaration-before-use order.
+
 2013-07-29  Mos´┐Ż Giordano  <address@hidden>
 
        * doc/changes.texi: Add other changes.
diff --git a/latex.el b/latex.el
index ae619a0..460027f 100644
--- a/latex.el
+++ b/latex.el
@@ -4062,44 +4062,108 @@ of verbatim constructs are not considered."
   "Mathematics in AUCTeX."
   :group 'LaTeX-macro)
 
-(defcustom LaTeX-math-list nil
-  "Alist of your personal LaTeX math symbols.
-
-Each entry should be a list with up to four elements, KEY, VALUE,
-MENU and CHARACTER.
+(defvar LaTeX-math-keymap (make-sparse-keymap)
+  "Keymap used for `LaTeX-math-mode' commands.")
 
-KEY is the key (after `LaTeX-math-abbrev-prefix') to be redefined
-in math minor mode.  If KEY is nil, the symbol has no associated
-keystroke \(it is available in the menu, though\).
+(defun LaTeX-math-abbrev-prefix ()
+  "Make a key definition from the variable `LaTeX-math-abbrev-prefix'."
+  (if (stringp LaTeX-math-abbrev-prefix)
+      (read-kbd-macro LaTeX-math-abbrev-prefix)
+    LaTeX-math-abbrev-prefix))
 
-VALUE can be a string with the name of the macro to be inserted,
-or a function to be called.  The macro must be given without the
-leading backslash.
+(defvar LaTeX-math-menu
+  '("Math"
+    ("Greek Uppercase") ("Greek Lowercase") ("Binary Op") ("Relational")
+    ("Arrows") ("Punctuation") ("Misc Symbol") ("Var Symbol") ("Log-like")
+    ("Delimiters") ("Constructs") ("Accents") ("AMS"))
+  "Menu containing LaTeX math commands.
+The menu entries will be generated dynamically, but you can specify
+the sequence by initializing this variable.")
 
-The third element MENU is the name of the submenu where the
-command should be added.  MENU can be either a string
-\(e.g. \"greek\"\), a list (e.g. \(\"AMS\" \"Delimiters\"\)\) or
-nil.  If MENU is nil, no menu item will be created.
+(defcustom LaTeX-math-menu-unicode
+  (or (string-match "\\<GTK\\>" (emacs-version))
+      (eq window-system 'w32))
+  "Whether the LaTeX menu should try using Unicode for effect."
+  :type 'boolean
+  :group 'LaTeX-math)
 
-The fourth element CHARACTER is a Unicode character position for
-menu display.  When nil, no character is shown.
+(defcustom LaTeX-math-abbrev-prefix "`"
+  "Prefix key for use in `LaTeX-math-mode'.
+This has to be a string representing a key sequence in a format
+understood by the `kbd' macro.  This corresponds to the syntax
+usually used in the Emacs and Elisp manuals.
 
-See also `LaTeX-math-menu'."
+Setting this variable directly does not take effect;
+use \\[customize]."
   :group 'LaTeX-math
-  :type '(repeat (group (choice :tag "Key"
-                               (const :tag "none" nil)
-                               (choice (character)
-                                       (string :tag "Key sequence")))
-                       (choice :tag "Value"
-                               (string :tag "Macro")
-                               (function))
-                       (choice :tag "Menu"
-                               (string :tag "Top level menu" )
-                               (repeat :tag "Submenu"
-                                       (string :tag "Menu")))
-                       (choice :tag "Unicode character"
-                               (const :tag "none" nil)
-                               (integer :tag "Number")))))
+  :initialize 'custom-initialize-default
+  :set '(lambda (symbol value)
+         (define-key LaTeX-math-mode-map (LaTeX-math-abbrev-prefix) t)
+         (set-default symbol value)
+         (define-key LaTeX-math-mode-map
+           (LaTeX-math-abbrev-prefix) LaTeX-math-keymap))
+  :type '(string :tag "Key sequence"))
+
+(defun LaTeX-math-initialize ()
+  (let ((math (reverse (append LaTeX-math-list LaTeX-math-default)))
+       (map LaTeX-math-keymap)
+       (unicode (and LaTeX-math-menu-unicode (fboundp 'decode-char))))
+    (while math
+      (let* ((entry (car math))
+            (key (nth 0 entry))
+            (prefix
+             (and unicode
+                  (nth 3 entry)))
+            value menu name)
+       (setq math (cdr math))
+       (if (and prefix
+                (setq prefix (decode-char 'ucs (nth 3 entry))))
+           (setq prefix (concat (string prefix) " \\"))
+         (setq prefix "\\"))
+       (if (listp (cdr entry))
+           (setq value (nth 1 entry)
+                 menu (nth 2 entry))
+         (setq value (cdr entry)
+               menu nil))
+       (if (stringp value)
+           (progn
+             (setq name (intern (concat "LaTeX-math-" value)))
+             (fset name (list 'lambda (list 'arg) (list 'interactive "*P")
+                              (list 'LaTeX-math-insert value 'arg))))
+         (setq name value))
+       (if key
+           (progn
+             (setq key (cond ((numberp key) (char-to-string key))
+                             ((stringp key) (read-kbd-macro key))
+                             (t (vector key))))
+             (define-key map key name)))
+       (if menu
+           (let ((parent LaTeX-math-menu))
+             (if (listp menu)
+                 (progn
+                   (while (cdr menu)
+                     (let ((sub (assoc (car menu) LaTeX-math-menu)))
+                       (if sub
+                           (setq parent sub)
+                         (setcdr parent (cons (list (car menu)) (cdr parent))))
+                       (setq menu (cdr menu))))
+                   (setq menu (car menu))))
+             (let ((sub (assoc menu parent)))
+               (if sub
+                   (if (stringp value)
+                       (setcdr sub (cons (vector (concat prefix value)
+                                                 name t)
+                                         (cdr sub)))
+                     (error "Cannot have multiple special math menu items"))
+                 (setcdr parent
+                         (cons (if (stringp value)
+                                   (list menu (vector (concat prefix value)
+                                                      name t))
+                                 (vector menu name t))
+                               (cdr parent)))))))))
+    ;; Make the math prefix char available if it has not been used as a prefix.
+    (unless (lookup-key map (LaTeX-math-abbrev-prefix))
+      (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command))))
 
 (defconst LaTeX-math-default
   '((?a "alpha" "Greek Lowercase" 945) ;; #X03B1
@@ -4626,107 +4690,47 @@ See also `LaTeX-math-menu'."
 Each entry should be a list with upto four elements, KEY, VALUE,
 MENU and CHARACTER, see `LaTeX-math-list' for details.")
 
-(defcustom LaTeX-math-abbrev-prefix "`"
-  "Prefix key for use in `LaTeX-math-mode'.
-This has to be a string representing a key sequence in a format
-understood by the `kbd' macro.  This corresponds to the syntax
-usually used in the Emacs and Elisp manuals.
+(defcustom LaTeX-math-list nil
+  "Alist of your personal LaTeX math symbols.
 
-Setting this variable directly does not take effect;
-use \\[customize]."
-  :group 'LaTeX-math
-  :initialize 'custom-initialize-default
-  :set '(lambda (symbol value)
-         (define-key LaTeX-math-mode-map (LaTeX-math-abbrev-prefix) t)
-         (set-default symbol value)
-         (define-key LaTeX-math-mode-map
-           (LaTeX-math-abbrev-prefix) LaTeX-math-keymap))
-  :type '(string :tag "Key sequence"))
+Each entry should be a list with up to four elements, KEY, VALUE,
+MENU and CHARACTER.
 
-(defun LaTeX-math-abbrev-prefix ()
-  "Make a key definition from the variable `LaTeX-math-abbrev-prefix'."
-  (if (stringp LaTeX-math-abbrev-prefix)
-      (read-kbd-macro LaTeX-math-abbrev-prefix)
-    LaTeX-math-abbrev-prefix))
+KEY is the key (after `LaTeX-math-abbrev-prefix') to be redefined
+in math minor mode.  If KEY is nil, the symbol has no associated
+keystroke \(it is available in the menu, though\).
 
-(defvar LaTeX-math-keymap (make-sparse-keymap)
-  "Keymap used for `LaTeX-math-mode' commands.")
+VALUE can be a string with the name of the macro to be inserted,
+or a function to be called.  The macro must be given without the
+leading backslash.
 
-(defvar LaTeX-math-menu
-  '("Math"
-    ("Greek Uppercase") ("Greek Lowercase") ("Binary Op") ("Relational")
-    ("Arrows") ("Punctuation") ("Misc Symbol") ("Var Symbol") ("Log-like")
-    ("Delimiters") ("Constructs") ("Accents") ("AMS"))
-  "Menu containing LaTeX math commands.
-The menu entries will be generated dynamically, but you can specify
-the sequence by initializing this variable.")
+The third element MENU is the name of the submenu where the
+command should be added.  MENU can be either a string
+\(e.g. \"greek\"\), a list (e.g. \(\"AMS\" \"Delimiters\"\)\) or
+nil.  If MENU is nil, no menu item will be created.
 
-(defcustom LaTeX-math-menu-unicode
-  (or (string-match "\\<GTK\\>" (emacs-version))
-      (eq window-system 'w32))
-  "Whether the LaTeX menu should try using Unicode for effect."
-  :type 'boolean
-  :group 'LaTeX-math)
+The fourth element CHARACTER is a Unicode character position for
+menu display.  When nil, no character is shown.
 
-(let ((math (reverse (append LaTeX-math-list LaTeX-math-default)))
-      (map LaTeX-math-keymap)
-      (unicode (and LaTeX-math-menu-unicode (fboundp 'decode-char))))
-  (while math
-    (let* ((entry (car math))
-          (key (nth 0 entry))
-          (prefix
-           (and unicode
-                (nth 3 entry)))
-          value menu name)
-      (setq math (cdr math))
-      (if (and prefix
-              (setq prefix (decode-char 'ucs (nth 3 entry))))
-         (setq prefix (concat (string prefix) " \\"))
-       (setq prefix "\\"))
-      (if (listp (cdr entry))
-         (setq value (nth 1 entry)
-               menu (nth 2 entry))
-       (setq value (cdr entry)
-             menu nil))
-      (if (stringp value)
-         (progn
-          (setq name (intern (concat "LaTeX-math-" value)))
-          (fset name (list 'lambda (list 'arg) (list 'interactive "*P")
-                           (list 'LaTeX-math-insert value 'arg))))
-       (setq name value))
-      (if key
-         (progn
-           (setq key (cond ((numberp key) (char-to-string key))
-                           ((stringp key) (read-kbd-macro key))
-                           (t (vector key))))
-           (define-key map key name)))
-      (if menu
-         (let ((parent LaTeX-math-menu))
-           (if (listp menu)
-               (progn
-                 (while (cdr menu)
-                   (let ((sub (assoc (car menu) LaTeX-math-menu)))
-                     (if sub
-                         (setq parent sub)
-                       (setcdr parent (cons (list (car menu)) (cdr parent))))
-                     (setq menu (cdr menu))))
-                 (setq menu (car menu))))
-           (let ((sub (assoc menu parent)))
-             (if sub
-                 (if (stringp value)
-                     (setcdr sub (cons (vector (concat prefix value)
-                                               name t)
-                                       (cdr sub)))
-                   (error "Cannot have multiple special math menu items"))
-               (setcdr parent
-                       (cons (if (stringp value)
-                                 (list menu (vector (concat prefix value)
-                                                    name t))
-                               (vector menu name t))
-                             (cdr parent)))))))))
-  ;; Make the math prefix char available if it has not been used as a prefix.
-  (unless (lookup-key map (LaTeX-math-abbrev-prefix))
-    (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command)))
+See also `LaTeX-math-menu'."
+  :group 'LaTeX-math
+  :set (lambda (symbol value)
+        (set-default symbol value)
+        (LaTeX-math-initialize))
+  :type '(repeat (group (choice :tag "Key"
+                               (const :tag "none" nil)
+                               (choice (character)
+                                       (string :tag "Key sequence")))
+                       (choice :tag "Value"
+                               (string :tag "Macro")
+                               (function))
+                       (choice :tag "Menu"
+                               (string :tag "Top level menu" )
+                               (repeat :tag "Submenu"
+                                       (string :tag "Menu")))
+                       (choice :tag "Unicode character"
+                               (const :tag "none" nil)
+                               (integer :tag "Number")))))
 
 (define-minor-mode LaTeX-math-mode
   "A minor mode with easy access to TeX math macros.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]