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 "."?

  • you can probably do so but it's a bit involved, not worth it. See emacs.stackexchange.com/questions/14058/… 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
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) ?.))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.