1

In Emacs, how can I make a macro, that is local to the HTML mode, and uses dashes and dots? Take a look at the Elisp below:

(define-abbrev-table 'html-mode-abbrev-table
   '(("..." "…")   ; won't work
     ("---" "—")    ; won't work
     ("aaa" "…")   ; works
     ("bbb" "—") )) ; works
Emanuel Berg
  • 6,763
  • 7
  • 43
  • 65

1 Answers1

1

Abbrevs can only contain characters that are considered word syntax as specified by the current buffer's syntax table. If you make "." and "-" word characters, then you can use them in abbrevs.

(require 'sgml-mode)
(modify-syntax-entry ?- "w" html-mode-syntax-table)
(modify-syntax-entry ?. "w" html-mode-syntax-table)

There are drawbacks. If you do regex searches using \w, then - and . are now going to be matched in any buffers using the altered syntax table. Cursor motion commands in those buffers will also be affected; e.g. forward-word will no longer stop before these characters. Similarly kill-word will delete more text than before. I think this behavior would be quite surprising and unpleasant in programming mode buffers, but in a text mode like HTML, I don't think it would cause much grief.

Kyle Jones
  • 14,845
  • 3
  • 40
  • 51
  • Are there any drawbacks to this? – Emanuel Berg Apr 04 '13 at 20:41
  • 1
    If you do regex searches using \w, dash and period are now going to be matched in buffers using the altered syntax table. Cursor motion commands will also be affected; forward-word will no longer stop before these characters. Similarly kill-word will delete more text than before. I think this behavior would be quite surprising and unpleasant in programming mode buffers, but in a text mode like HTML, I don't think it would cause much grief. – Kyle Jones Apr 04 '13 at 22:24
  • Aha, no, cursor movement and word killing are holy cows. I'll have to find another solution. I'll leave this question open for some time, if there is no other suggestion, I'll accept your answer. Because in a way it is correct, although I won't use it. – Emanuel Berg Apr 04 '13 at 23:14