help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: "Smart" quotes and dashes in PSGML


From: Kevin Rodgers
Subject: Re: "Smart" quotes and dashes in PSGML
Date: Mon, 21 Jul 2003 12:04:29 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

D. D. Brierton wrote:

I write (X)HTML documents in Emacs using PSGML mode. At the moment,
whenever I've finished a document I do various search-and-replaces to get
proper punctuation marks, such as replacing ' with ’, -- with
–, --- with —, and " with either “ or ”. I was
wondering whether anyone had written a function which would do that
automatically as I type, rather like lots of word processors do,


You could rebind those characters like this:

(defun xhtml-insert-entity-reference (character)
  "Insert the XHTML entity reference for CHARACTER."
  (interactive (list (aref (this-command-keys) 0)))
  (if (equal character ?\")
      (insert (completing-read "” or “? " '(("”")
                                                        ("“"))
                               nil t "&"))
    (insert (cdr (assoc character
                        '(?' "’")
                        ...
                        )))))

(add-hook sgml-mode-hook
          (lambda ()
            (if (string-match "\\.xhtml\\'" buffer-file-name)
                (progn
                  (local-set-key "'" 'xhtml-insert-entity-reference)
                  ...))))

Or you could create a w3c-xhtml.map file in the same format as the
iso88591.map file, with all the XHTML character entities, then:

(add-hook sgml-mode-hook
          (lambda ()
            (if (string-match "\\.xhtml\\'" buffer-file-name)
                (set (make-local-variable sgml-display-char-list-filename)
                     "~/w3c-xhtml.map")))) ; or wherever you install it

But neither way can handle multiple characters like "--" and "---".

(With either technique, you would use `C-q' to insert the literal character.)

but which
would not touch anything within a tag (such as the quote marks around
attribute values, or the comment markers)?

Perhaps xhtml-insert-entity-reference above could be modified like this:


  (let ((element (sgml-last-element)))
    (or (eq element sgml-top-tree)
        (and (eq (sgml-element-gi element) sgml-pcdata-token)
             (if (equal character ?\")
                 (insert ...)
               (insert ...)))))

--
Kevin Rodgers



reply via email to

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