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!

  • 2
    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 at 14:16
7

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()
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.

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.