[Top][All Lists]

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

[AUCTeX] feature request

From: Joost Kremers
Subject: [AUCTeX] feature request
Date: Tue, 16 Jan 2007 01:54:35 +0100
User-agent: Mutt/1.5.12-2006-07-14


Although I've been using AUCTeX for a couple of years, I've recently
started looking at it a bit closer, and am discovering lots of nice things,
esp. preview-latex and tex-fold. With regards to the latter I have a small
feature request:

Right now, the macros (and environments) to be folded can be visually
represented either with a fixed string or with a specific argument of the
macro. What I'd like is the ability to specify a function that is to be
called, with the arguments of the macro as arguments to the function.

Background: I'd like \cite{jones:1988} to be folded as "(jones:1988)",
i.e. with parentheses, instead of either just "[c]" or "jones:1988".

(More background: in principle, you could get this functionality if
TeX-fold-macro-spec-list would allow some form of format sting,
e.g. "(#1)", where #1 gets replaced with the first argument of the macro to
be folded. But I wrote an Elisp program to manage my .bib-files with, so I
have easy access to the database entry associated with a certain
cite-key. Using that, I'd be able to fold a harvard.sty command such as
\citeyear{texbook} into "(1984)", or \citename{texbook} into "Knuth",
extracting the data from the .bib database.)

To (better) show what I mean, I hacked together the patch below to
tex-fold.el. With this patch, I can add an entry to
TeX-fold-macro-spec-list of the form

 ((lambda (x) (format "(%s)" x))

which will fold the \cite macro with a parenthesised version of the first

(Note: this "patch" is just to show what I mean. Though it works for me
ATM, it's not very robust: it completely ignores text properties in
XEmacs, for example, and I haven't given any thought to what would be the
least error-prone way to actually do this...)




--- tex-fold.el 2006-12-29 14:40:19.000000000 +0100
+++ tex-fold.mod.el     2007-01-16 01:13:26.000000000 +0100
@@ -84,7 +84,8 @@
        "textbf" "textsc" "textup")))
   "List of display strings and macros to fold."
   :type '(repeat (group (choice (string :tag "Display String")
-                               (integer :tag "Number of argument" :value 1))
+                               (integer :tag "Number of argument" :value 1)
+                               (function :tag "Function to execute"))
                        (repeat :tag "Macros" (string))))
   :group 'TeX-fold)
@@ -658,10 +659,21 @@
   (let* ((ov-start (overlay-start ov))
         (ov-end (overlay-end ov))
         (spec (overlay-get ov 'TeX-fold-display-string-spec))
-        (computed (if (stringp spec)
-                      spec
-                    (or (TeX-fold-macro-nth-arg spec ov-start ov-end)
-                        "[Error: No content found]")))
+        (computed (cond
+                   ((stringp spec) spec)
+                   ((functionp spec)
+                    (let ((arg-list nil)
+                          (n 1)
+                          (arg ""))
+                      (while (setq arg (TeX-fold-macro-nth-arg n ov-start 
+                        (add-to-list 'arg-list (car arg) t)
+                        (setq n (1+ n)))
+                      (or (condition-case nil
+                              (apply spec arg-list)
+                            (error nil))
+                          "[Error: No content or function found]")))
+                   (t (or (TeX-fold-macro-nth-arg spec ov-start ov-end)
+                          "[Error: No content found]"))))
         (display-string (if (listp computed) (car computed) computed))
         (face (when (listp computed) (cadr computed))))
     ;; Cater for zero-length display strings.


Joost Kremers, PhD
University of Cologne
Institute for German Language and Literature
Albertus Magnus Platz
50923 Cologne, Germany
Tel. +49 221 / 4703807

reply via email to

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