4

I've looked for a solution to this a number of times. Suppose 'kg' normally expands to 'knowledge' in my abbrev file. I wonder if there is any way to get emacs to expand after a single or double quotation mark, as in expanding from

"kg

to

"knowledge

I don't know lisp well but am willing to play with my .emacs. Thanks for any help!

Edit: I just noticed that it works fine in the scratch buffer, but not in markdown or LaTeX modes.

  • It's technically a small bug in LaTeX mode, because it redefines the double quote key and so the abbrev doesn't expand. What's your emacs version, I can write you a workaround. – Malabarba Mar 28 '15 at 23:44
  • GNU Emacs 24.3.1 - but it happens in markdown mode too, where the quotation-mark substitution does not take place. – Steve Petersen Mar 29 '15 at 19:54
2

How about this?

(with-eval-after-load 'tex-mode
 (defun expand-and-insert-space ()
  (interactive)
  (expand-abbrev)
  (insert "\ ")))

(define-key latex-mode-map (kbd "<SPC>") 'expand-and-insert-space)
(define-key latex-mode-map (kbd "<M-/>") 'expand-abbrev)

EDITED to include eval-after-load

  • 1
    Hmm thanks! I tried that but got Symbol's value as variable is void: latex-mode-map. Unfortunately this means little to me. – Steve Petersen Nov 24 '15 at 17:42
  • 2
    Could be fixed by wrapping in (with-eval-after-load 'tex-mode ...). – npostavs Jul 20 '16 at 18:50
  • Sorry I only just saw this answer - I guess I don't have notifications on. It seems to work, thanks! To be clear, I just add that first code line, (with-eval-after-load 'tex-mode (defun expand-and-insert-space () (interactive) (expand-abbrev) (insert "\ "))) - right? – Steve Petersen Aug 1 '16 at 13:23
  • You should add the whole thing so that you can remap the space key. This is a hacky workaround and won't expand, for instance, when you hit delimiters like , and . unless you redefine those also. – incandescentman Aug 2 '16 at 3:04

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.