From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leu Zhe Subject: Using font-lock-add-keywords to display caption than various table and images headers Date: Thu, 24 Apr 2014 15:23:09 +0900 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1133e4ca6a98ec04f7c3e417 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdD4Z-0005oR-JD for emacs-orgmode@gnu.org; Thu, 24 Apr 2014 02:23:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WdD4Y-00079S-Ew for emacs-orgmode@gnu.org; Thu, 24 Apr 2014 02:23:51 -0400 Received: from mail-qa0-x233.google.com ([2607:f8b0:400d:c00::233]:33093) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdD4Y-00079O-8a for emacs-orgmode@gnu.org; Thu, 24 Apr 2014 02:23:50 -0400 Received: by mail-qa0-f51.google.com with SMTP id j7so1846679qaq.38 for ; Wed, 23 Apr 2014 23:23:49 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --001a1133e4ca6a98ec04f7c3e417 Content-Type: text/plain; charset=ISO-8859-1 According to the http://stackoverflow.com/questions/22937393/emacs-lisp-prettify-symbols-mode-for-latexby 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! --001a1133e4ca6a98ec04f7c3e417 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
According to the=A0http://sta= ckoverflow.com/questions/22937393/emacs-lisp-prettify-symbols-mode-for-late= x by using font-lock-add-keywords, I can display the latin symbols inst= ead of the English word like \alpha without changing the real contents. It = is pretty great.=A0

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 :=A0

#+= CAPTION: caption
#+ATTR_LaTeX: :align |c|c|
#+LABEL: ta= ble:label
| name | value |
|------+-------|
| tony | =A0 =A030 |

After re-display:
=

table:label caption
| name | value |
|------+-------|
| tony | =A0 =A030 |

=
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-alis= t
=A0 (cl-pairlis '("#\\+CAPTION: \\(.+$\\)\n#= \\+ATTR_LaTeX.+\n#\\+LABEL: \\(.+$\\)")
=A0 =A0 =A0 = =A0 =A0 =A0 =A0 ("test")))
(def= un pretty-things()
=A0 (mapc
=A0 =A0(lambda (x)
=A0 =A0 =A0(let ((wor= d (car x))
=A0 =A0 =A0 =A0 =A0 =A0(char (cdr x)))
=A0 = =A0 =A0 =A0(font-lock-add-keywords
=A0 =A0 =A0 =A0 nil
= =A0 =A0 =A0 =A0 `((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word &quo= t;\\)[a-zA-Z]")
=A0 =A0 =A0 =A0 =A0 =A0 (0 (progn
=A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0(decompose-region (match-beginning 2) (match-end 2))
= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0nil)))))
=A0 =A0 =A0 =A0(font-= lock-add-keywords
=A0 =A0 =A0 =A0 nil
=A0 =A0 =A0 =A0 `= ((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[^a-zA-Z]&qu= ot;)
=A0 =A0 =A0 =A0 =A0 =A0 (0 (progn
=A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0(compose-region (1- (match-beginning 2)) (match-end 2)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ,char)
=A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0nil)))))))
=A0 =A0pretty-alist))


the results are below:

<= div>test
| name | value |
|------+-------|
| tony | =A0 =A030 |

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

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 art= icles.

Thanks very much. Any help will be very appreciated.=A0=

Best regard!
--001a1133e4ca6a98ec04f7c3e417--