emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Leu Zhe <lzhes43@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Using font-lock-add-keywords to display caption than various table and images headers
Date: Thu, 24 Apr 2014 15:23:09 +0900	[thread overview]
Message-ID: <CALjq+LbDMLceuGY5RQq=hceJD9ZxmLyc4z5ib-GpL9m+DBvKKA@mail.gmail.com> (raw)

[-- 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 --]

                 reply	other threads:[~2014-04-24  6:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALjq+LbDMLceuGY5RQq=hceJD9ZxmLyc4z5ib-GpL9m+DBvKKA@mail.gmail.com' \
    --to=lzhes43@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).