Hot answers tagged

24

Here is how completion in company works (I am simplifying a bit a more detailed description can be found in documentation of company-backends C-hvcompany-backendsRET. You have a list of backends (completion engines) company should try to provide completion at point. Company tries each of this backend one after the another and the first one that returns any ...


8

I'd use yasnippet for this, especially because of the desired cursor placement. The first snippet could be something like # -*- mode: snippet -*- # name: dots # key: dots # -- \dots{$0} You should store this file in a directory named latex-mode under a directory that is listed in yas-snippet-dirs. I think the official documentation is probably the best ...


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: M-x define-global-abbrev fp with np.printoptions(threshold=np.inf): print()


6

Let me refer you to my post on this. I've found that abbrevs are the best way to do correction on SPC, you only need to define the corrections that you want. For that, I take the following approach: Add the code below to your init file. Whever you type something wrong, hit C-x C-i and choose one of the corrections offered. That's it! The correction will be ...


5

Yes: just put a non-nil value for the :case-fixed property. (define-abbrev my-foo-abbrev-table "r" "EmacsRocks" nil :case-fixed t) See C-h v define-abbrev RET for more details.


5

You could either hack the syntax table so as not to treat the : as a non-word constituent, or you could write an :enable-function that will prevent expansion on the basis of :. This one works: (define-abbrev-table 'text-mode-abbrev-table '(("eq" "equation")) "My table." :enable-function (lambda () (let* ((vec (this-command-keys-...


5

You could use a pre-abbrev-expand-hook to delete the extra space before the abbrev is expanded like this: (defun delete-preceding-space-before-expand () (when (and (= (char-after) ?\s) ;; only do if expanded with space (= last-command-event ?\s) (abbrev--before-point)) (message "%S" last-command-event) (...


5

Yes, you can tell the abbrev table to use an explicit function to test whether or not to fire in a given instance. The relevant argument in define-abbrev-table is :enable-function, which, according to the docstring, reads: (define-abbrev-table TABLENAME DEFINITIONS &optional DOCSTRING &rest PROPS) Define TABLENAME (a symbol) as an abbrev ...


5

Out of the box it is not possible with the abbrev system since self-insert-command calls expand-abbrev only when a non-word character is to be inserted. Citation from the doc string of expand-abbrev: Before insertion, ‘expand-abbrev’ is executed if the inserted character does not have word syntax and the previous character in the buffer does. So we ...


4

The manual says the following. Subskeletons are inserted recursively, not once, but as often as the user enters something at the subskeletons interactor. Thus there must be a str in the subskeleton. They can also be used non-interactively, when prompt is a lisp-expression that returns successive list-elements. (Emphasis is mine, see section Skeleton ...


4

company-mode has a files backend:


4

You could try something like this: add additional behavior to "e" itself. Make it insert by default, but try to expand otherwise (defun e-insert-or-expand () "Insert 'e', and if it is part of an abbrev, expand the abbrev" (interactive) (insert "e") (expand-abbrev)) (global-set-key "e" 'e-insert-or-expand) If you want to refine this to only ...


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


3

I asked the same question recently on emacs-devel and Kenichi Handa told me I could do: (defvar my-TeX-input-method-tweaked nil) (defun my-quail-activate-hook () (when (and (not (member (quail-name) my-TeX-input-method-tweaked)) (member (quail-name) '("TeX" "latin-1-prefix"))) (quail-defrule "uu" "ū") (push (...


3

You can continue to use abbrev-mode. The following elisp snippet allows you to specify additional characters as word-consistent when abbreviation takes place. After running the snippet customize the option abbrev-additional-chars with an alist that maps major-mode symbols to the lists of characters that should be interpreted as word-consistent during ...


3

Found the Solution: the verilog-mode does fill the "abbrev-table" every time it gets initialized. I added a hook to my spacemacs-dotfile which clears the table after the mode is initialized: (defun my-verilog-setup () (clear-abbrev-table verilog-mode-abbrev-table)) (add-hook 'verilog-mode-hook #'my-verilog-setup)


3

In Org, you're looking for (org) Easy Templates; try typing <sTAB: With just a few keystrokes, Org’s easy templates inserts empty pairs of structural elements, such as ‘#+BEGIN_SRC’ and ‘#+END_SRC’. Easy templates use an expansion mechanism, which is native to Org, in a process similar to ‘yasnippet’ and other Emacs template expansion packages. ‘<...


3

First, note that abbrevs expand when typing a word separator character, not just space. Looking at the doc for self-insert-command suggests that's no way to easily change the behavior of abbrev-mode. self-insert-command is an interactive built-in function in ‘src/cmds.c’. (self-insert-command N) Insert the character you type. Whichever ...


2

Here's a simple attempt: (defun my-flyspell-correct-on-space () (interactive) (when flyspell-mode (flyspell-auto-correct-word)) (self-insert-command 1)) (local-set-key " " 'my-flyspell-correct-on-space) It behaves strangely when you insert more than one space in a row, and sometimes it splits off part of the word being corrected. Thus this post ...


2

I'm not sure if this is what you are looking for, but the package you linked to can be extended to capture abbrev expansion like so: (require 'volatile-highlights) (volatile-highlights-mode t) (vhl/define-extension 'abbrev 'expand-abbrev) (vhl/install-extension 'abbrev)


2

Note: The accepted answer on this question is not the optimal solution! Changing the syntax table is not neccesary to alter the behaviour of what is expanded and what not. By default emacs uses indeed word syntax, i.e. non-word characters like _ and / etc. can not occur in an abbrev. However, this behaviour can be customized per abrrev-table. See Sect. ...


2

Abbrev expansion behavior is built into the C code that implements self-insert-command. It looks up the syntactic class of the current and previous character in the buffer's syntax table to decide whether to expand abbreviations. In a programming mode for a language where the underscore is an identifier constituent, you may want to change _ to have word ...


2

This should be take care of it. It disables abbrev mode for any key you want. It's similar to the other answer, but you don't need to define a new function for each key. (defun self-insert-no-abbrev () (interactive) (let ((abbrev-mode nil)) (call-interactively 'self-insert-command))) (global-set-key "_" #'self-insert-no-abbrev) (global-set-key "." #...


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


2

Ha! There's a subtle bug in your code: the 3rd argument of define-abbrev-table is the docstring, so it treats :enable-function as the docstring and the subsequent function as a property name (with missing value).


2

Yasnippet can do what you want. Either a shortcut key-binding or a prefix substring can expand to a particular snippet. And each snippet can present a list of options via yas-choose-value. Here is an example snippet based on your example: -- mode: snippet; require-final-newline: nil -- name: st key: st binding: direct-keybinding -- ${1:$$(yas-choose-...


2

You need undo-boundary. For example: (defun abel-expand () "Expand the abbrev before point." (when (= (length (this-command-keys-vector)) 1) (insert-char (aref (this-command-keys-vector) 0)) (undo-boundary) (backward-delete-char 1)) (unless (memq (aref (this-command-keys-vector) 0) '(?- ?+ ?/ ?_)) (when (looking-at "[])} ]") (...


2

define-abbrev accepts a predicate, just use it to specify the abbrev should only expand when requested explicitly. (define-abbrev text-mode-abbrev-table "dem" "democracy" nil :enable-function (lambda () (eq this-command 'expand-abbrev))) The above abbrev will not expand when you hit SPC (or any other self-inserting character), but it will expand when you ...


2

when you define a abbrev table, you can add a property to specify regex on what chars to look for. Example: (define-abbrev-table 'xah-elisp-abbrev-table '( ("d" "(defun f▮ ()\n \"DOCSTRING\"\n (interactive)\n (let (VAR)\n\n ))" nil :system t) ("i" "(insert ▮)" nil :system t) ("l" "(let (x▮)\n x\n)" nil :system t) ("m" "(message \"%s▮\"...


2

Calling a (set (make-local-variable 'abbrev-file-name) 'My-current-abbrev-file) preceding this read-abbrev-file should help.


Only top voted, non community-wiki answers of a minimum length are eligible