7

I find using abbrevs in Emacs confusing. Despite reading the manual and the EmacsWiki, I continue to have problems using them.

Goal:

Define a quick, throw-away abbrev for a single Emacs session.

Example:

When using Python and Numpy, outputs are sometimes shortened with an ellipsis:

array(['1007.65', '1007.63', '1007.66', ..., '993.40', '993.40', '993.57'],
      dtype=object)

To display the array in full, you need to issue this mouthful of a statement:

with np.printoptions(threshold=np.inf): print(my_arr['field_name'])

This seems like a perfect situation for an abbrev!

Here's what I do:

  1. Type fp for "full print"
  2. With point immediately after p in fp, issue C-x a g (add-global-abbrev)
  3. In the minibuffer prompt for Global abbrev for "fp":, put with np.printoptions(threshold=np.inf): print() and press <RET>
  4. The minibuffer exits, returning me to my original buffer with point after p in fp
  5. Issue C-x a e (expand-abbrev)

Nothing happens.

If I check list-abbrevs, there it is:

(global-abbrev-table)

"with np.printoptions(threshold=np.inf): print()" 0 "fp"

My understanding is that I don't need abbrev-mode enabled, as that's only used for automatic expansion. Incidentally, enabling abbrev-mode still doesn't expand fp.

I'm at a loss for what I'm doing wrong and would appreciate some advice!

Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
  • 3
    Since you read the Emacs doc about this but interpreted the behavior backward, please consider telling Emacs about the problem and perhaps suggest some different wording: `M-x report-emacs-bug`. It's likely that you are not the only person to have gotten this backward. Perhaps the doc should include an example? – Drew Mar 13 '19 at 14:16

2 Answers2

8

You defined your abbrev backwards - "with np.printoptions(threshold=np.inf): print()" will expand to "fp" with what you've done!

To define a multi-word abbrev, you should do:

  1. M-x define-global-abbrev
  2. fp
  3. with np.printoptions(threshold=np.inf): print()
Tyler
  • 21,719
  • 1
  • 52
  • 92
2

What about

  1. Put point immediately after p in fp.
  2. Issue C-x a i g (inverse-add-global-abbrev).
  3. Enter with np.printoptions(threshold=np.inf): print() and press RET.
  4. C-x a e

BTW I have abbrev-mode switched on all the time and it almost always helps and almoste never gets in my way.

Marco Wahl
  • 2,796
  • 11
  • 13