emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] Re: Indenting <example> tags


From: Sacha Chua
Subject: [emacs-wiki-discuss] Re: Indenting <example> tags
Date: Wed, 22 Jun 2005 22:02:13 +0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

Michael Olson <address@hidden> writes:

> Try adding the following to your .emacs.
> (defun emacs-wiki-example-tag (beg end highlight-p)

Hmm, this deletes all starting whitespace, which breaks
nicely-indented code segments.

What about this?

   (defun emacs-wiki-example-tag (beg end highlight-p)
     (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))
       ;; Figure out how much whitespace precedes the example tag
       (let (offset)
         (goto-char beg)
         (when (looking-back (concat "^[" emacs-wiki-regexp-blank "]+"))
           (setq offset (concat "^" (match-string 0)))
           (replace-match "")
           (setq beg (point)))
         (save-restriction
           (narrow-to-region (point) end)
           (insert "<pre class=\"example\">")
           (when offset
             (while (re-search-forward offset nil t)
               (replace-match "")
               (forward-line)))
           (emacs-wiki-escape-html-specials end)
           (goto-char (point-max))
           (insert "</pre>"))
         (add-text-properties beg (point) '(rear-nonsticky (read-only)
                                                           read-only t)))))


Mind you, the prefix whitespace needs to be exactly the same right now... =)
-- 
Sacha Chua <address@hidden> - open source geekette
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C
interests: emacs, gnu/linux, personal information management, CS ed
sachac on irc.freenode.net#emacs . YM: sachachua83




reply via email to

[Prev in Thread] Current Thread [Next in Thread]