[Top][All Lists]

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

[AUCTeX-devel] [RFC] Adding TeX-arg-verb-delim-or-brace to latex.el

From: Arash Esbati
Subject: [AUCTeX-devel] [RFC] Adding TeX-arg-verb-delim-or-brace to latex.el
Date: Wed, 21 Feb 2018 22:02:27 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3

Hi all,

some macros like \url from url.sty take their argument in braces \url{ }
or delimiters \url| |.  I would like to add the function
`TeX-arg-verb-delim-or-brace' to latex.el and would then update the
style (and others like minted.el und listings.el).  The current
implementation ist attached.  Eval the forms in the verbatim environment
and try `C-c C-m url RET'.  Any comments welcome.

--8<---------------cut here---------------start------------->8---


(defun TeX-arg-verb-delim-or-brace (optional &optional prompt)
  "Prompt for delimiter and text.
If OPTIONAL, indicate optional argument in minibuffer.  PROMPT is
a string replacing the default one when asking the user for
  (let ((del (read-quoted-char
              (concat "Delimiter (default "
                      (char-to-string LaTeX-default-verb-delimiter) "): "))))
    (when (<= del ?\ )
      (setq del LaTeX-default-verb-delimiter))
    (if (TeX-active-mark)
          (insert del)
          (goto-char (mark))
          ;; If the delimiter was an opening brace, close it with a
          ;; brace, otherwise use the delimiter again
          (if (= del ?\{)
              (insert ?\})
            (insert del)))
      ;; Same thing again
      (insert del (read-from-minibuffer
                   (TeX-argument-prompt optional prompt "Text"))
              (if (= del ?\{)
    ;; Do not set `LaTeX-default-verb-delimiter' if the user input was
    ;; an opening brace.  This would give funny results for the next
    ;; "C-c C-m \verb RET"
    (unless (= del ?\{)
      (setq LaTeX-default-verb-delimiter del))))

(TeX-add-symbols '("url" (TeX-arg-verb-delim-or-brace "Url"))
                 '("path" (TeX-arg-verb-delim-or-brace "Path")))

(add-to-list 'LaTeX-verbatim-macros-with-delims-local "url")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")

(font-latex-add-keywords '(("path" "") ("url" "")) 'reference)
(font-latex-update-font-lock t)

\url|www| \url{www}

--8<---------------cut here---------------end--------------->8---

Best, Arash

reply via email to

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