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

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

Using punctuation in abbrev


From: Aurélien Aptel
Subject: Using punctuation in abbrev
Date: Sat, 1 Jun 2013 19:41:55 +0200

Hi,

I want to substitute $-> with a unicode rightwards arrow (U+2192  →).
Since abbrev defaults to backward-word to extract the word before
point, I've used the :regexp property of an abbrev-table to define
what to extract.

>From define-abbrev-table documentation:

  - `:regexp' is a regular expression that specifies how to extract the
    name of the abbrev before point.  The submatch 1 is treated
    as the potential name of an abbrev.  If :regexp is nil, the default
    behavior uses `backward-word' and `forward-word' to extract the name
    of the abbrev, which can therefore only be a single word.

Here's what I put in my init file:

  (define-abbrev-table 'global-abbrev-table '(
                                              ("$->" "→")
                                              ("$=>" "⇒")
                                              ("$foo" "X")
                                              )
    "custom abbrev table"
    :regexp (rx (or bos bol space) (group (+ (not space)))))
  (setq save-abbrevs nil)
  (setq-default abbrev-mode t)

But only the $foo substitution works and I can't figure out why.
The regex seems to be correct:

(let ((rx (rx (or bos bol space) (group (+ (not space)))))
      (slist '(" $->" "\n$=>" " $foo")))
  (mapcar (lambda (s) (string-match-p rx s)) slist))

=> (0 0 0)



reply via email to

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