Commit graph

23 commits

Author SHA1 Message Date
theschmocker
406594b9af refactor(snippets): use cond instead of nested if 2023-08-19 21:59:48 -05:00
theschmocker
363706744d feat(snippets): select mode for new snippet
When there are extra yasnippet modes loaded in the current buffer,
prompt user to select one for the new snippet.

If a prefix arg is supplied when calling `+snippets/new`, prompt user to
select any mode.
2023-08-19 21:49:51 -05:00
theschmocker
4643376268 fix(snippets): fix +snippets/new and +snippets/new-alias file creation
When adding a snippet/alias to a mode for the first time, setting
`default-directory` before calling `+snippet--ensure-dir` would cause an
error due to the directory not existing. As a fix, return the dir from
`+snippet--ensure-dir` and bind `default-directory` to that.

Additionally, not having a file associated with the buffer caused issues
with loading the snippet after using snippet-mode's C-c C-c binding,
especially when other directories were added to yasnippet's load paths.
As a solution for this, prompt the user for a snippet key and set the
buffer's file name to it within the snippet dir. If an existing file
would be overwritten, ask user for confirmation. As an additional
convenience, set the snippet's key field to the entered value.

Finally, replace %alias with doom-snippets-expand in the generated alias
snippets. Not aware of any history here, but %alias did not work for me.
2023-08-19 21:49:11 -05:00
theschmocker
41f31ba9ce fix(snippets): fix snippet uuid completion
Rather than attempting to read the uuid from a text property on the
selected completion -- which gets stripped by vertico (and possibly
helm) -- grab it from a lookup alist of completion-candidat->uuid.

Essentially the same as the proposed implementation by @jgrey4296
on #4127

Fix: #4127
2023-08-19 21:00:15 -05:00
HyunggyuJang
33e922645b
fix(snippets): yas-expand error on yas-choose-value (#5429)
`+snippets-prompt-private` was overzealous intercepting the candidates fed to
`yas-choose-value`. For example, expanding the `jupyter` snippet in org mode
results in:

\#+begin_src jupyter-Wrong type argument: yas--template, "python" :session :async yes
...
\#+end_src
2021-09-15 18:59:43 +02:00
Henrik Lissner
06392a723f refactor: rename orig-fn arg in advice to fn
A minor tweak to our naming conventions for the first argument of an
:around advice.
2021-08-04 01:53:12 -04:00
Seth Mason
6ebbd94b89 Prompt should say edit and not alias. 2021-02-13 14:20:12 -08:00
Sam Whitlock
670c8d519d Inlining the uuid function 2021-01-07 11:40:50 +01:00
Sam Whitlock
c0c932ae09 Improving snippet lookup behavior
This enables snippets to be accessed by UUID in parent modes of the
current mode. Prior behavior was to only look up for the current mode,
but the active modes (and those suggested in the prompt) include
parent-mode snippets (e.g., text-mode snippets when major-mode is org-mode).
2021-01-07 09:05:18 +01:00
Henrik Lissner
2772ca8e70
Conditionally switch to insert mode on snippet expansion
If already in insert (or emacs) state, don't switch mode when expanding
a yasnippet snippet.
2020-12-11 15:50:02 -05:00
Henrik Lissner
523ced6e9a
Fix #4127: arrayp error on some snippets via +snippets/edit 2020-11-14 14:16:01 -05:00
Henrik Lissner
d8fda76c7d
yas-also-auto-indent-first-line = nil
Stop yasnippet from aggressively reindenting the whole snippet; assume
the user is expanding the snippet exactly where they want it.

Half-fixes #3211
2020-05-24 14:29:41 -04:00
Henrik Lissner
e10cd8cf2e
Insult byte-compiler's mom
Yeah, that shut him up.
2019-09-20 23:10:53 -04:00
Henrik Lissner
a3e262c7ac
💥 Refactor add-hook! macro & change arg order
This update may potentially break your usage of add-hook! if you pass
the :local or :append properties to it. This is how they used to work:

  (add-hook! :append 'some-mode-hook #'do-something)

Thsoe properties must now follow the hooks, e.g.

  (add-hook! 'some-mode-hook :append #'do-something)

Other changes:
- Various add-hook calls have been renamed to add-hook! because I
  incorrectly assumed `defun` always returned its definition's symbol,
  when in fact, its return value is "undefined" (so sayeth the
  documentation). This should fix #1597.
- This update adds the ability to add multiple functions to hooks
  without a list:

    (add-hook! 'some-mode-hook
               #'do-something
               #'do-something-else)

- The indentation logic has been changed so that consecutive function
  symbols at indented at the same level as the first argument, but forms
  are indent like a defun.

    (add-hook! 'some-mode-hook
               #'do-something
               #'do-something-else)

    (add-hook! 'some-mode-hook
      (message "Hello"))
2019-07-26 20:17:29 +02:00
Henrik Lissner
81ab3dbc5d
Simplify and decouple init files
The two doom-gc-* variables in init.el couples the rest of the config to
these two files. The bulk of GC/file-handler optimization was moved into
core.el and simplified (all that idle-timer voodoo was overkill).

Also adds (setq frame-inhibit-implied-reize t) to early-init, which
speeds up startup a fair bit in some edge cases with larger fonts.

squash! Simplify and decouple init files
2019-07-22 02:30:38 +02:00
Henrik Lissner
62af55dad0
Move emacs-snippets -> doom-snippets
The repo was renamed upstream.
2019-07-14 17:05:48 +02:00
Henrik Lissner
05eb333a0c
editor/snippets: expand on snippet commands & keybinds
- Introduces the +snippets/new (SPC s n) command for creating a new
  private snippet
- Introduces the +snippets/new-lias (SPC s N) command for creating a new
  private snippet alias, which will invoke another snippet (you will be
  prompted to select one). This will only work with the emacs-snippets
  library bundled with Doom Emacs, however, as it depends on its API.
- Introduces +snippets/edit (SPC s c) for modifying existing snippets.
  How this differs from yas-visit-snippet-file is it will copy the
  contents of built-in snippets into a buffer primed for your private
  snippets (in DOOMDIR/snippets), while yas-visit-snippet-file will
  simply open the originating snippet.
- Introduces the +snippets/find (SPC s ?),
  +snippets/find-for-current-mode (SPC s /) and
  +snippets/find-private (SPC s f) commands for, respectively, finding a
  snippet file among *all* directories in yas-snippet-dirs, finding a
  snippet for the current major mode (plus parents), and finding a
  snippet from among your private library. This opens built-in snippets
  in read-only mode, but you can press C-c C-e to open it in
  +snippets/edit.
2019-07-12 20:41:50 +02:00
Henrik Lissner
a201409fdd
Minor refactors across the board 2019-07-10 21:27:12 +02:00
Henrik Lissner
e8c0ac9f30
Switch to insert mode after expanding snippets 2019-07-10 12:08:39 +02:00
Henrik Lissner
9a02bd8ac8
Minor refactors across the board
- when-let* -> when-let
- Fix projectile-locate-dominating-file for connected remote files
2019-06-26 14:31:06 +02:00
Henrik Lissner
dcdebdb283
Convert +snippets/expand-on-region to advice
It's meant to be corrective, not alternative behavior.
2019-06-10 09:38:51 +02:00
Henrik Lissner
a4f9eb6f6c
Enable read-only-mode for built-in snippets
Because they shouldn't be edited out of ~/.emacs.d/.local -- if a
snippet in ~/.doom.d/snippets has the same name, built-in snippets will
be ignored.
2019-04-24 18:16:05 -04:00
Henrik Lissner
77e4cc4d58
💥 Remove :feature category
:feature was a "catch-all" category. Many of its modules fit better in
other categories, so they've been moved:

- feature/debugger -> tools/debugger
- feature/evil -> editor/evil
- feature/eval -> tools/eval
- feature/lookup -> tools/lookup
- feature/snippets -> editor/snippets
- feature/file-templates -> editor/file-templates
- feature/workspaces -> ui/workspaces

More potential changes in the future:

- A new :term category for terminal emulation modules (eshell, term and
  vterm).
- A new :os category for modules dedicated to os-specific functionality.
  The :tools macos module would fit here, but so would modules for nixos
  and arch.
- A new :services category for web-service integration, like wakatime,
  twitter, elfeed, gist and pastebin services.
2019-04-24 18:16:04 -04:00
Renamed from modules/feature/snippets/autoload/snippets.el (Browse further)