5

Let's say abbrev expands "com" into "commission".

The problem is that this expands "google.com" into "google.commission".

Is there a way to disable this expansion if "com" is preceded by a "."?

scaramouche
  • 1,772
  • 10
  • 24
  • you can probably do so but it's a bit involved, not worth it. See http://emacs.stackexchange.com/questions/14058/how-to-use-abbrev-for-words-with-dollar-sign-as-prefix also read the elisp manual on abbrev. – Xah Lee Sep 25 '16 at 15:34
  • instead, I'd recommend just make your abbrev zcom. Whenever you have abbrev that'll clash, add z in front. Or, prefix z for all your abbrevs. – Xah Lee Sep 25 '16 at 15:35

1 Answers1

3

I ended up solving this question using the :enable-function in define-abbrev-table (similar to what's recommended here: Do not expand a given abbrev when followed by ":").

My solution is to put all my abbreviations in the global-abbrev-table and all my exceptions in text-mode-abbrev-table. Then have an enable-function that checks that the character preceding the current word is not a ".".

(defun my-char-preceding-word ()
  (interactive)
  (save-excursion
    (backward-word)
    (char-before)))

(define-abbrev-table 'text-mode-abbrev-table
  '(("com" "commission"))
  "My exceptions table."
  :enable-function (lambda ()
                     (not (eq (my-char-preceding-word) ?.))))
scaramouche
  • 1,772
  • 10
  • 24