29

I have the following snippet in my configuration and it seems like it's exactly what you want: ;; Add yasnippet support for all company backends ;; https://github.com/syl20bnr/spacemacs/pull/179 (defvar company-mode/enable-yas t "Enable yasnippet for all backends.") (defun company-mode/backend-with-yas (backend) (if (or (not company-mode/enable-yas) (...


23

This is what I created for myself, facing the same issue. It is from company-mode's Emacs Wiki page, but heavily extended: (defun check-expansion () (save-excursion (if (looking-at "\\_>") t (backward-char 1) (if (looking-at "\\.") t (backward-char 1) (if (looking-at "->") t nil))))) (defun do-yas-expand () (let ((yas/...


18

The Yasnippet documentation explains that you will need to include a .yas-parents file with the parent modes: It's very useful to have certain modes share snippets between themselves. To do this, choose a mode subdirectory and place a .yas-parents containing a whitespace-separated list of other mode names. When you reload those modes become parents of the ...


12

You should rewrite your snippet so that the backquoted expression doesn't modify the buffer, but instead returns the string to insert: # -*- coding: utf-8 -*- # name: date # key: date # -- `(format-time-string "%Y-%m-%d")`$0 For more examples, see yasnippet truncates clipboard contents


11

SHORT SOLUTION If you do not mind an additional TAB keystroke, definining your snippet as below should work. [[${1:`(dan-xclipboard-link-p)`}][$0]] The embedded lisp returns the url from the clipboard if it exists and sets it to be the default text in the field $1. You can type over the link to change it or just TAB (yas-next-field) to move point to $0. ...


11

M-/ is the default binding to expand snippets not TAB. You can find this out with Spc ? then searching for yas


10

Here's the code that I'm using: (global-set-key "\C-o" 'aya-open-line) (defun aya-open-line () "Call `open-line', unless there are abbrevs or snippets at point. In that case expand them. If there's a snippet expansion in progress, move to the next field. Call `open-line' if nothing else applies." (interactive) (cond ((expand-abbrev)) ((yas--...


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


8

warning-suppress-types is a list defined in the warnings package. You first need to load this package with: (require 'warnings) and after this, add the warning using add-to-list: (add-to-list 'warning-suppress-types '(yasnippet backquote-change))


7

I added the following code to solve most of my problem: (setq ac-source-yasnippet nil) But, it caused complexity between yasnippet and auto-complete so I added this: (define-key yas-minor-mode-map (kbd "<tab>") nil) (define-key yas-minor-mode-map (kbd "TAB") nil) (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand) Modified some ...


7

As of 2017, Jan 22, if you set org-src-tab-acts-natively and org-src-fontify-natively, then TAB in source blocks will expand snippets of the block's language. You may want to set yas-buffer-local-condition to stop org mode snipppets from shadowing the block mode's snippets: (defun my-org-mode-hook () (setq-local yas-buffer-local-condition '(...


6

It's a snippet, activated with yasnippet. Notice how it starts with a comment character, this hinted to me that it wasn't an org-mode feature. Why would org-mode comment out a todo? I have something similar that I got from this snippet repository, but it only works in modes derived from prog-mode (which excludes org-mode). However, the snippets directory ...


6

As a workaround, you can redefine the Yasnippet expansion key instead, as explained in the FAQ: (define-key yas-minor-mode-map (kbd "<tab>") nil) (define-key yas-minor-mode-map (kbd "TAB") nil) (define-key yas-minor-mode-map (kbd "<C-tab>") 'yas-expand) In this way, you use <C-tab> to expand Yasnippets and the TAB key for auto-complete-...


6

Function to capitalize only the first char Make sure that the below function is evaluated in your emacs config before the yasnippet snippets are loaded. (defun my/capitalize-first-char (&optional string) "Capitalize only the first character of the input STRING." (when (and string (> (length string) 0)) (let ((first-char (substring string nil ...


6

Just remembered it was auto-insert-mode. Make a new elisp file, run M-x auto-insert, and it prompts for summary, author, inserts the license and everything.


6

Customize the value of yas-snippet-dirs so that it doesn't include the default snippet directory. On recent yasnippet versions this will be the symbol yas-installed-snippets-dir. yas-snippet-dirs is a variable defined in `yasnippet.el'. Its value is ("~/.emacs.d/snippets" yas-installed-snippets-dir) Documentation: List of top-level snippet directories. ...


6

Use the expand-env directive, as described in the manual. E.g. # expand-env: ((yas-indent-line 'fixed) (yas-wrap-around-region 'nil))


6

I ran into a similar issue, and wrote a stand-alone function to get around the weird interactions between yasnippet and polymode. The following function mimics the behaviour of the snippet you tried, prompting first for the header info, which gets inserted at your $1, and then dropping you in the chunck body (your $0): (defun tws-insert-r-chunk (header) ...


6

Simply change the value of the variable yas-snippet-dirs, which by default includes yas-installed-snippets-dir (pointing to the builtin snippets - those that you want ignored/disabled). For example: (setq yas-snippet-dirs '("~/.emacs.d/mysnippets")) ... asuming you have your own custom snippets at the above location (or at least the empty folder created ...


6

You can load an additional modes via yas-activate-extra-mode in the hook of the major mode (it also works with yas-global-mode turned on). Just copy-paste following elisp snippet into your init file: (defun my-org-latex-yas () "Activate org and LaTeX yas expansion in org-mode buffers." (yas-minor-mode) (yas-activate-extra-mode 'latex-mode)) (add-...


5

No, you don't need to do anything. Actually, you can't even do anything about it without patching the source of the affected package. Generally, as a user you don't need to be concerned about warnings. Only if you actually develop packages, you should care about warnings in your packages, and try to fix them. However, if you like to, you can report the ...


5

Customize yas-keymap for that. (eval-after-load 'yasnippet '(progn (define-key yas-keymap (kbd "TAB") nil) (define-key yas-keymap (kbd "C-o") 'yas-next-field-or-maybe-expand)))


5

yas-reload-all is the correct way to tell yasnippet about updates to yas-snippet-dirs (aka yas/root-directory), recompilation is not needed. yas/initialize is basically an obsolete way of saying (yas-global-mode +1), hence your python-mode-hook is redundant. yas-global-mode also calls yas-reload-all when it's turned on, so if you just set yas-snippet-dirs ...


5

The # binding: header documented in the manual is the official method to do this. It's implemented using emulation-mode-map-alists which means it will override any other major or minor mode keybindings, except for packages which also use emulation-mode-map-alists, typically emulation packages like Evil. I noticed it will work when you're in insert mode of ...


5

To have a value repeat like you're asking, simply repeat the $N. For example, I have this for snippet: # -*- mode: snippet; require-final-newline: nil -*- # name: for # key: for # -- for(${1:int} ${2:i} = 0; $2 < ${3:N}; $2++) { $0 } The default expansion is: for(int i = 0; i < N; i++) { //cursor } It only prompts for the first instance of $...


5

Try this snippet: # -*- mode: snippet -*- # name: cout variable # key: cvar # -- cout << "${1:var} = " << $1 << endl;$0 I believe the main problem is that yasnippet doesn't recognize the second ${1:} as a mirroring placeholder, and instead attempts to fix the snippet by changing ${1:} to ${2:}. It may be an idea to open an issue on ...


4

Is there an option in yasnippets to automatically indent each line according to the mode's default indentation of the line? This is what setting yas-indent-line to 'auto is for, except that you also want to set yas-also-auto-indent-first-line to t. I guess it defaults to nil because it causes problems in some cases.


4

You can tell yasnippet to interpret its type as a command rather than a snippet to interpret the body as lisp code. The following example allows you to enter LaTeX environments (e.g., as if you had used C-c C-e): # -*- mode: snippet -*- # name: environment # key: env # type: command # -- (call-interactively #'LaTeX-environment) And here's another option ...


4

I use the following which is a mashup of the standard doxymacs based one and abo-abo's semantic based one mentioned as an answer already - this only requires semantic and yasnippet. This pre-populates some more of the yasnippet placeholders with relevant info as well compared to abo-abo 's version too. # -*- mode: snippet -*- # name: dox # key: dox # type: ...


4

From yas-minor-mode does not load snippets (GitHub): I think when not using yas-global-mode you have to at least add a (yas-reload-all) call somewhere to your .emacs. This will setup the jit-loading tables (and not load actual snippets until yas-minor-mode is activated in some buffer for which one of those tables has been setup. It might be ...


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