6194 comments
2357 subscribers
Follow me on Twitter (@sachac)
Subscribe! Feed reader E-mail

Better!

Finally got emacs-wiki highlighting just the way I want it.
Apparently, it bypasses the normal font-lock thing. Changes: I made
the example tag remove all the properties from the bounded region.
Here’s the relevant snippet from my ../emacs/emacs-wiki-config.el:

(defun sacha/htmlfontify-insert-region (buffer begin end)
  "Insert into BUFFER the htmlified text between BEGIN and END."
  (save-excursion
    (let* ((hfy-optimisations (cons 'skip-refontification hfy-optimisations))
	   (input-text (buffer-substring begin end))
	   (temp-file (make-temp-file "html-input"))
	   output-buffer)
      (with-temp-buffer
	(insert input-text)
	(setq buffer-file-name temp-file)
	(save-excursion (setq output-buffer (htmlfontify-buffer nil nil)))
	(set-buffer-modified-p nil))
      (unwind-protect
	  (let (b e yanked-output)
	    (set-buffer output-buffer)
	    (goto-char (point-min))
	    (search-forward "
\n")
	    (setq b (line-beginning-position))
	    (goto-char (point-max))
	    (search-backward "

")
(forward-line -1)
(setq e (line-beginning-position))
(setq yanked-output (buffer-substring-no-properties b e))
(set-buffer buffer)
(insert yanked-output))
(set-buffer output-buffer)
(set-buffer-modified-p nil)
(delete-file temp-file)
(kill-buffer output-buffer)))))

(defun sacha/emacs-wiki-example-tag (beg end attrs highlight-p)
"Mark up text as an example with optional font-locking."
(if highlight-p
(progn
(remove-text-properties
beg end '(face nil font-lock-multiline nil
invisible nil intangible nil display nil
mouse-face nil keymap nil help-echo nil))
(goto-char end))
;; I don't know what would happen if you don't have
;; htmlfontify. I guess if you are installing this you
;; should have it...
(let ((end-marker (set-marker (make-marker) (1+ end))))
(save-restriction
(narrow-to-region beg end)
(let* ((mode (cdr (assoc "mode" attrs)))
(start (progn (forward-line) (point)))
(stop (progn (goto-char end) (beginning-of-line) (point)))
(text (buffer-substring-no-properties start stop))
(buffer (current-buffer)))
(delete-region beg end)
(with-temp-buffer
(insert text)
(when (and mode (and (stringp mode) (functionp (intern mode))))
(funcall (intern mode))
(font-lock-fontify-buffer))
(sacha/htmlfontify-insert-region buffer (point-min) (point-max)))
(goto-char (point-min))
(insert "

\n")
	  (goto-char (point-max))
	  (insert "

\n")
(add-text-properties (point-min) (point-max)
'(rear-nonsticky (read-only) read-only t))))
(goto-char end-marker))))

(add-hook 'emacs-wiki-mode-hook 'emacs-wiki-highlight-buffer t)

Short URL: http://sachachua.com/blog/p/1789

On This Day...

  • 2013: Appreciating people — I’ve been thinking about friendship as one of those things that I want to deliberately get better at through practice [...]
  • 2012: Experience report: Applying for a Harmonized Sales Tax account — In Canada, corporations are required to collect and remit Harmonized Sales Tax if their revenues are over $30,000 in a [...]
  • 2010: On vintage portaits and wedding photography — With my dad and my sister both professional photographers, I have a deep appreciation for the way pictures can bring [...]
  • 2008: You have received a painting from Sacha
  • 2008: Networking 2.0: Blogging Your Way out of a Job… and Into a Career — Blog for FREE on wordpress.com or blogger.com! Make a habit of writing at least once a week, and your blog [...]
  • 2007: For the win! — I *like* this feeling. Rowr! I called up the property management building for the apartment I’m renting starting March. I wanted to [...]
  • 2006: Debian’s still alive! — What do you know… Debian’s still accepting applications after all! =) I just got e-mail from the Debian Account Manager, months [...]
  • 2006: Insulated — For all the chaos and turmoil rocking the Philippines—from natural disasters like the landslide that buried a village to man-made disasters like [...]
  • 2006: Hooray for Ateneo! — Didith Rodrigo has plenty of great news: Google’s sponsoring the students’ trip to the ACM finals again! Hooray! Numerous contests here and [...]
  • 2006: Snuggling up — Check out Accordion Guy’s post about snuggling up. It’s soooo cuuuuuute! =)
  • 2005: Stock photography — http://www.indexstock.com is an online stock photography service. Check out the guidelines. I think this is a good service for us to look [...]
  • 2005: File transfers: Xdrive — Xdrive looks like a promising way to transfer files between clients. It’s an additional USD 9.95 a month for 5 GB. If [...]
  • 2004: Better font-locking in emacs-wiki — If you’re having problems with emacs-wiki not highlighting the first time you view a buffer, you’re probably set to use jit-lock [...]
  • 2004: Ledger — Depends: libxmltok1 libpcre3 libgmp3 Build-deps: libxmltok1-dev libpcre3-dev libgmp3-dev
  • 2004: emacs-wiki and the example tag — I firmly believe that stuff in example tags should not get marked up on the page, and may have to fiddle [...]
  • 2004: Bah, unrelated repositories — * patching for this revision (mark@dishevelled.net--2003-mst/emacs-wiki--dev--1.0--patch-1) star-merge: unable to merge unrelated trees.
  • 2004: Public key needed for XEmacs packages — I was getting “Couldn’t check signature” errors on XEmacs. I uncommented the mailto keyserver in my ~/.gnupg/gpg.conf and now things work. The [...]
  • 2004: planner.el goodness — Andrew Laing wrote: I think the work you put into Planner et al is fantastic. I have spent quite a bit of [...]
  • 2004: Printer details — Deleted: Lost secret key
  • 2003: some comments about my outfit — Apparently, a short black velvet dress and a brilliant red-and-yellow obi-style belt is sufficiently unusual that it draws comments from the other [...]
  • 2003: departmental award for computer science — It looks like my chances for getting it are very, very slim, because I’ve got a D
  • 2003: thesis defense — Thesis defense on Monday, 2:00 – 2:30. Dr. Vergara, Ma’am Estuar, Dr. Sarmenta
  • 2003: rescheduling classes — Dr. Sarmenta’s thinking of giving me back the CS21B. He needs to confirm with Sir Marco. I don’t know where Sir [...]