emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using font-lock-add-keywords to display caption than various table and images headers
@ 2014-04-24  6:23 Leu Zhe
  0 siblings, 0 replies; only message in thread
From: Leu Zhe @ 2014-04-24  6:23 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2194 bytes --]

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!

[-- Attachment #2: Type: text/html, Size: 3213 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-24  6:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-24  6:23 Using font-lock-add-keywords to display caption than various table and images headers Leu Zhe

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).