Subject: mailing-list for TeXmacs Users
List archive
From : Lukasz Stafiniak <address@hidden>- To: address@hidden
- Subject: [TeXmacs] Highlighting source code using "highlight".
- Date: Sun, 26 Feb 2012 21:19:13 +0100
- Authentication-results: mr.google.com; spf=pass (google.com: domain of address@hidden designates 10.180.83.70 as permitted sender) smtp.mail=address@hidden; dkim=pass header.i=address@hidden
Hi,
I use the attached code to "highlight" (using the command of this
name) a code sample in Emacs and copy it to TeXmacs. Most of the work
is done in Emacs since I studied Emacs more (long, long ago) and it is
better at self documenting. I struggled to find a way to put comments
side-by-side, or over code, finally I stumbled upon "tab" -- I hadn't
realized its power. Each line of the inserted code has place to
provide plain-text comments. Since it is for slides and I have bigger
than standard magnification for them, I paste the code inside \tiny or
\very-small, so the \small size of comments is really bigger than the
code.
Perhaps someone can provide me with code that combines "Edit / Clear"
(bound to M-g) and "Edit / Paste from / LaTeX" and binds it to a key?
(For example, code to put into "my-init-texmacs.scm".) Here's my
emacs-side binding:
;; Copy a highlighted in latex code sample to clipboard.
(load-file (concat system-home-path "Emacs/prepare-highlight.el"))
(global-set-key (kbd "C-c w") 'latex-highlight-code-region)
Cheers!
<TeXmacs|1.0.7.14>
<style|source>
<\body>
<assign|hlstd|<macro|codetext|<verbatim|<with|color|#000000|<arg|codetext>>>>>
<assign|hlnum|<macro|codetext|<verbatim|<with|color|#000040|<arg|codetext>>>>>
<assign|hlesc|<macro|codetext|<verbatim|<with|color|#BC8C8C|<arg|codetext>>>>>
<assign|hlstr|<macro|codetext|<verbatim|<with|color|#BC8C8C|<arg|codetext>>>>>
<assign|hlpps|<macro|codetext|<verbatim|<with|color|#BC8C8C|<arg|codetext>>>>>
<assign|hlslc|<macro|codetext|<verbatim|<with|color|#AA2121|<arg|codetext>>>>>
<assign|hlcom|<macro|codetext|<verbatim|<with|color|#AA2121|<arg|codetext>>>>>
<assign|hlppc|<macro|codetext|<verbatim|<with|color|#000000|<arg|codetext>>>>>
<assign|hlopt|<macro|codetext|<verbatim|<with|color|#404060|<arg|codetext>>>>>
<assign|hllin|<macro|codetext|<verbatim|<with|color|#545454|<arg|codetext>>>>>
<assign|hlkwa|<macro|codetext|<verbatim|<with|color|#9B21ED|<arg|codetext>>>>>
<assign|hlkwb|<macro|codetext|<verbatim|<with|color|#218921|<arg|codetext>>>>>
<assign|hlkwc|<macro|codetext|<verbatim|<with|color|#0000FF|<arg|codetext>>>>>
<assign|hlkwd|<macro|codetext|<verbatim|<with|color|#000000|<arg|codetext>>>>>
<assign|textunderscore|<macro|_>>
<assign|textasciicircum|<macro|^>>
<assign|hlline|<\macro|codeline>
<arg|codeline><line-break>
</macro>>
<assign|hlendline|<macro|comment|<htab|5mm><small|<arg|comment>>>>
</body>
<\initial>
<\collection>
<associate|language|american>
</collection>
</initial>(defun prepare-latex-highlight-code ()
"Preprocess a latex buffer produced by `highlihgt'."
(interactive)
(save-excursion
(goto-char 0)
(while (search-forward "\\textasciicircum " nil t)
(replace-match "{\\textasciicircum}" t t))
(goto-char 0)
(while (search-forward "\\textunderscore " nil t)
(replace-match "{\\textunderscore}" t t))
(goto-char 0)
(while (search-forward-regexp
"^\\(.*\\)\\\\hspace\\*{\\\\fill}\\\\\\\\$" nil t)
;(replace-match "\\\\hlline{\\1}" t)
(replace-match "\\1\\\\hlendline{}\\\\\\\\" t))
))
(defun latex-highlight-code-region (reg-start reg-end)
"Copy a `highlight'ed in latex code sample, for insertion in TeXmacs
using the `highlight' style package."
(interactive "r")
(save-excursion
(let*
((file-ext (downcase (file-name-extension (buffer-name))))
(highlight-kind
(assoc-default
file-ext
'(("lpr" . "pas")
("pp" . "pas")
("fp" . "pas")
("ml" . "ocaml")
("mli" . "ocaml")
("fs" . "fsharp")
("fsx" . "fsharp")
("hs" . "haskell")
("flx" . "felix")
)
nil
file-ext))
(hl-command (concat "highlight -Olatex -S" highlight-kind)))
(shell-command-on-region reg-start reg-end hl-command))
(switch-to-buffer "*Shell Command Output*")
(prepare-latex-highlight-code)
(search-forward "\\ttfamily" nil t)
(let ((hlres-beg (point)))
(search-forward "\\mbox{}" nil t)
(end-of-line 0)
(let ((hlres-end (point)))
(clipboard-kill-region hlres-beg hlres-end)))
(kill-buffer "*Shell Command Output*")
))
- [TeXmacs] Highlighting source code using "highlight"., Lukasz Stafiniak, 02/26/2012
- [TeXmacs] Re: Highlighting source code using "highlight"., Lukasz Stafiniak, 02/27/2012
Archive powered by MHonArc 2.6.19.