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

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

[elpa] externals/auctex 8e13306 66/71: Update style/url.el to package ve


From: Tassilo Horn
Subject: [elpa] externals/auctex 8e13306 66/71: Update style/url.el to package version 3.4
Date: Fri, 17 Dec 2021 15:00:38 -0500 (EST)

branch: externals/auctex
commit 8e133062a06726e58f4d13d338ad339db00f1512
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>

    Update style/url.el to package version 3.4
    
    * style/url.el: Add parsing abilities for the macros \urldef and
    \DeclareUrlCommand.
    (TeX-arg-url-urlstyle): New function renamed from
    `TeX-arg-urlstyle'.
    (TeX-arg-url-DeclareUrlCommand, TeX-arg-url-urldef): New
    functions.
    ("url"): Remove macros for setting new styles, linebreaks
    etc. from fontification.  Move '\urlstyle' to function class.
    (LaTeX-url-package-options): Update package options.
---
 style/url.el | 181 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 147 insertions(+), 34 deletions(-)

diff --git a/style/url.el b/style/url.el
index eafbd90..8c186cf 100644
--- a/style/url.el
+++ b/style/url.el
@@ -26,7 +26,7 @@
 
 ;;; Commentary:
 
-;; This file adds support for `url.sty'.
+;; This file adds support for `url.sty' v3.4 dated 2013-09-16.
 
 ;;; Code:
 
@@ -41,11 +41,131 @@
 (declare-function font-latex-set-syntactic-keywords
                   "font-latex")
 
+;; Setup for \DeclareUrlCommand:
+(TeX-auto-add-type "url-DeclareUrlCommand" "LaTeX")
+
+(defvar LaTeX-url-DeclareUrlCommand-regexp
+  `(,(concat
+      "\\\\DeclareUrlCommand"
+      "[ \n\r\t]*"
+      "{?"
+      "\\\\\\([a-zA-Z]+\\)"
+      "}?")
+    1 LaTeX-auto-url-DeclareUrlCommand)
+  "Matches the argument of `\\DeclareUrlCommand' from `url' package.")
+
+(defun LaTeX-url-DeclareUrlCommand-prepare ()
+  "Process macros parsed from `\\DeclareUrlCommand'."
+  ;; \DeclareUrlCommand\abc{settings}: makes \abc{ } like \url{ } with
+  ;; settings.
+  (when (LaTeX-url-DeclareUrlCommand-list)
+    (dolist (cmd (mapcar #'car (LaTeX-url-DeclareUrlCommand-list)))
+      (TeX-add-symbols `(,cmd TeX-arg-verb-delim-or-brace))
+      (add-to-list 'LaTeX-verbatim-macros-with-delims-local cmd)
+      (add-to-list 'LaTeX-verbatim-macros-with-braces-local cmd))
+    ;; Fontification
+    (when (and (fboundp 'font-latex-add-keywords)
+               (fboundp 'font-latex-set-syntactic-keywords)
+               (eq TeX-install-font-lock 'font-latex-setup))
+      (font-latex-add-keywords
+       (mapcar (lambda (cmd)
+                 (list cmd  ""))
+               (mapcar #'car (LaTeX-url-DeclareUrlCommand-list)))
+       'reference)
+      ;; Tell font-lock about the update.
+      (font-latex-set-syntactic-keywords))))
+
+;; Setup for \urldef:
+(TeX-auto-add-type "url-urldef" "LaTeX")
+
+(defvar LaTeX-url-urldef-regexp
+  `(,(concat
+      "\\\\urldef"
+      "[ \n\r\t]*"
+      "{?"
+      "\\\\\\([a-zA-Z]+\\)"
+      "}?")
+    1 LaTeX-auto-url-urldef)
+  "Matches the argument of `\\urldef' from `url' package.")
+
+(defun LaTeX-url-urldef-prepare ()
+  "Process macros parsed from `\\urldef'."
+  (when (LaTeX-url-urldef-list)
+    (mapc #'TeX-add-symbols (mapcar #'car (LaTeX-url-urldef-list)))
+    ;; Fontification
+    (when (and (fboundp 'font-latex-add-keywords)
+               (eq TeX-install-font-lock 'font-latex-setup))
+      (font-latex-add-keywords
+       (mapcar (lambda (cmd)
+                 (list cmd ""))
+               (mapcar #'car (LaTeX-url-urldef-list)))
+       'reference))))
+
+(defun LaTeX-url-auto-prepare ()
+  "Clear `LaTeX-auto-url-*' before parsing."
+  (setq LaTeX-auto-url-DeclareUrlCommand nil
+        LaTeX-auto-url-urldef            nil))
+
+(defun LaTeX-url-auto-cleanup ()
+  "Process parsed elements from url.sty."
+  (LaTeX-url-DeclareUrlCommand-prepare)
+  (LaTeX-url-urldef-prepare))
+
+(add-hook 'TeX-auto-prepare-hook #'LaTeX-url-auto-prepare t)
+(add-hook 'TeX-auto-cleanup-hook #'LaTeX-url-auto-cleanup t)
+(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+
+(defun TeX-arg-url-urlstyle (optional &optional prompt)
+  "Prompt for style used in \\urlstyle with completion.
+If OPTIONAL is non-nil, indicate it in the minibuffer during the
+query and insert the result in brackets.  PROMPT replaces the
+standard one."
+  (TeX-argument-insert
+   (completing-read (TeX-argument-prompt optional prompt "Style")
+                    '("rm" "same" "sf" "tt"))
+   optional))
+
+(defun TeX-arg-url-DeclareUrlCommand (optional &optional prompt)
+  "Prompt for arguments of \\DeclareUrlCommand with completion.
+If OPTIONAL is non-nil, indicate it in the minibuffer during the
+query and insert the result in brackets.  PROMPT replaces the
+standard one."
+  (let ((cmd (TeX-read-string
+              (TeX-argument-prompt optional prompt "Command: \\" t)))
+        (style (completing-read
+                (TeX-argument-prompt optional prompt "Style")
+                '("rm" "same" "sf" "tt"))))
+    (insert TeX-esc cmd TeX-grop)
+    (when (and style (not (string= style "")))
+      (insert TeX-esc "urlstyle" TeX-grop style TeX-grcl))
+    (insert TeX-grcl)
+    (LaTeX-add-url-DeclareUrlCommands cmd)
+    (LaTeX-url-DeclareUrlCommand-prepare)))
+
+(defun TeX-arg-url-urldef (optional &optional prompt)
+  "Prompt for arguments of \\urldef with completion."
+  (let ((cmd (TeX-read-string
+              (TeX-argument-prompt optional prompt "Command: \\" t))))
+    (TeX-argument-insert cmd optional TeX-esc)
+    (LaTeX-add-url-urldefs cmd)
+    (LaTeX-url-urldef-prepare))
+  (TeX-insert-macro
+   (completing-read
+    (TeX-argument-prompt optional prompt "Macro: \\" t)
+    (append (mapcar #'car (LaTeX-url-DeclareUrlCommand-list))
+            '("url")))))
+
 (TeX-add-style-hook
  "url"
  (lambda ()
+
+   ;; Add url to the parser
+   (TeX-auto-add-regexp LaTeX-url-DeclareUrlCommand-regexp)
+   (TeX-auto-add-regexp LaTeX-url-urldef-regexp)
+
    ;; New symbols
    (TeX-add-symbols
+    ;; Macros for defining new styles, changing font, linebreaks etc.
     "Url"
     "UrlBigBreakPenalty"
     "UrlBigBreaks"
@@ -57,56 +177,49 @@
     "UrlOrds"
     "UrlRight"
     "UrlSpecials"
-    '("path" (TeX-arg-verb-delim-or-brace "Path"))
+
     ;; "hyperref" redefines \url so that the argument is only in
     ;; braces.  We check here if hyperref is loaded:
     '("url" (TeX-arg-conditional (member "hyperref" (TeX-style-list))
                                  ("Url")
                                  ((TeX-arg-verb-delim-or-brace "Url"))))
-    "urldef"
-    '("urlstyle" TeX-arg-urlstyle))
 
-   (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
-   ;; hyperref.el has some code to remove "url" from
-   ;; `LaTeX-verbatim-macros-with-delims-local', but we check here as
-   ;; well if "hyperref" is already loaded:
+    '("urldef" TeX-arg-url-urldef)
+
+    '("urlstyle" TeX-arg-url-urlstyle))
+
+   ;; For '\path', use the facilities provided by this style.  Also
+   ;; don't add "path" for fontification below since
+   ;; `LaTeX-url-urldef-prepare' takes care of it.
+   (LaTeX-add-url-DeclareUrlCommands "path")
+   (LaTeX-url-urldef-prepare)
+
+   ;; Don't do the same for '\url' because hyperref.el has some code
+   ;; to remove "url" from `LaTeX-verbatim-macros-with-delims-local',
+   ;; but we check here as well if "hyperref" is already loaded:
    (unless (member "hyperref" (TeX-style-list))
      (add-to-list 'LaTeX-verbatim-macros-with-delims-local "url"))
-   (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
    (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
 
    ;; Fontification
    (when (and (fboundp 'font-latex-add-keywords)
               (eq TeX-install-font-lock 'font-latex-setup))
-     (font-latex-add-keywords '(("path" "") ("url" "")) 'reference)
-     (font-latex-add-keywords '(("Url" "")
-                                ("UrlBigBreakPenalty" "")
-                                ("UrlBigBreaks" "")
-                                ("UrlBreakPenalty" "")
-                                ("UrlBreaks" "")
-                                ("UrlFont" "")
-                                ("UrlLeft" "")
-                                ("UrlNoBreaks" "")
-                                ("UrlOrds" "")
-                                ("UrlRight" "")
-                                ("UrlSpecials" "")
-                                ("urldef" "")
-                                ("urlstyle" "{"))
-                              'variable)
+     (font-latex-add-keywords '(("url" ""))
+                              'reference)
+     ;; Don't fontify the second argument of 'DeclareUrlCommand' since
+     ;; it gets the `font-latex-verbatim-face' from the first
+     ;; argument.  Same applies also to '\urldef' where we don't
+     ;; fontify any arguments:
+     (font-latex-add-keywords '(("DeclareUrlCommand" "\\")
+                                ("urldef"            "")
+                                ("urlstyle"          "{"))
+                              'function)
      ;; Tell font-lock about the update.
      (font-latex-set-syntactic-keywords)))
  TeX-dialect)
 
-(defun TeX-arg-urlstyle (optional &optional prompt)
-  "Prompt for style used in \\urlstyle with completion."
-  (TeX-argument-insert
-   (completing-read (TeX-argument-prompt optional prompt "Style")
-                    '("rm" "same" "sf" "tt")
-                    nil t)
-   optional))
-
-(defvar LaTeX-url-package-options '("hyphens" "obeyspaces" "spaces" "LY1"
-                                    "T1" "allowmove")
+(defvar LaTeX-url-package-options '("hyphens" "obeyspaces" "spaces"
+                                    "allowmove" "lowtilde")
   "Package options for the url package.")
 
 ;;; url.el ends here



reply via email to

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