emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Using font-lock-add-keywords to display caption than various table a


From: Leu Zhe
Subject: [O] Using font-lock-add-keywords to display caption than various table and images headers
Date: Thu, 24 Apr 2014 15:23:09 +0900

According to the http://stackoverflow.com/questions/22937393/emacs-lisp-prettify-symbols-mode-for-latex by using font-lock-add-keywords, I can display the latin symbols instead of the English word like \alpha without changing the real contents. It is pretty great. 

Then a good idea came to my brain, which is: Can i use this feature to display the caption and label of the table and image rather than headers which holds at least three lines? If it can be accomplished, which will make the article very compact and easier to read:

Before re-display : 

#+CAPTION: caption
#+ATTR_LaTeX: :align |c|c|
#+LABEL: table:label
| name | value |
|------+-------|
| tony |    30 |

After re-display:

table:label caption
| name | value |
|------+-------|
| tony |    30 |

I tried to alter some part of the code using regexp search to find the headers and capture the caption and label contents, and test to re-display the matched contents to test:

(defvar pretty-alist
  (cl-pairlis '("#\\+CAPTION: \\(.+$\\)\n#\\+ATTR_LaTeX.+\n#\\+LABEL: \\(.+$\\)")
              ("test")))
(defun pretty-things()
  (mapc
   (lambda (x)
     (let ((word (car x))
           (char (cdr x)))
       (font-lock-add-keywords
        nil
        `((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[a-zA-Z]")
            (0 (progn
                 (decompose-region (match-beginning 2) (match-end 2))
                 nil)))))
       (font-lock-add-keywords
        nil
        `((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[^a-zA-Z]")
            (0 (progn
                 (compose-region (1- (match-beginning 2)) (match-end 2)
                  ,char)
                 nil)))))))
   pretty-alist))


the results are below:

test
| name | value |
|------+-------|
| tony |    30 |

Then i tried to change the "test" to "\\2 \\1", error of 'no function \\2 \\1' appeared. It seems like that the the second parameter of cl-pairlis must be a function. 

I am a pretty beginner to elisp, so it is very hard for me to solve this problem, then i decide to ask for help here.
If it can be accomplished, it will be really a progress to read and write articles.

Thanks very much. Any help will be very appreciated. 

Best regard!

reply via email to

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