Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-completion always load snippets shipped by default #7092

Closed
hghwng opened this issue Sep 12, 2016 · 6 comments
Closed

Auto-completion always load snippets shipped by default #7092

hghwng opened this issue Sep 12, 2016 · 6 comments

Comments

@hghwng
Copy link
Contributor

hghwng commented Sep 12, 2016

Description

Auto-completion layer always loads the snippet shipped by yasnippet. See packages.el:237

        ;; ~/.emacs.d/elpa/yasnippet-xxxxx/snippets
        (push 'yas-installed-snippets-dir yas-snippet-dirs)

The desired behavior is:

  • If private-yas-dir (set by variable auto-completion-private-snippets-directory or generated from configuration-layer-private-directory) is found in file system, yas-installed-snippets-dir should be ignored.
  • If the variable like auto-completion-enable-snippets-shipped-by-default is set, yas-installed-snippets-dir will be used regardless of whether private-yas-dir is detected.

Pro:

  • More intuitive behavior
  • Simpler configuration: no more manual variable tweaking

Con:

  • May break the existing configuration.

Reproduction guide

  • Start Emacs
  • SPC h d v, yas-snippet-dirs
  • elpa/yasnippet-xxx/snippet is seen in the list

Relevant config

     (auto-completion :variables
                      auto-completion-enable-help-tooltip t
                      auto-completion-enable-snippets-in-popup nil)

System Info

  • OS: gnu/linux
  • Emacs: 24.5.1
  • Spacemacs: 0.105.22
  • Spacemacs branch: master (rev. 9f9faa4)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(better-defaults eyebrowse smex git shell ranger
                 (auto-completion :variables auto-completion-enable-help-tooltip t auto-completion-enable-snippets-in-popup nil auto-completion-private-snippets-directory "~/.emacs.d/private/snippets")
                 spell-checking syntax-checking
                 (chinese :variables chinese-enable-fcitx t chinese-enable-youdao-dict t)
                 (c-c   :variables c-c  -enable-clang-support nil c-c  -default-mode-for-headers 'c  -mode)
                 (ycmd :variables ycmd-server-command
                       '("python" "/home/hugh/.config/utils/pkg/ycmd/ycmd")
                       ycmd-global-config "/home/hugh/.spacemacs.d/global_config.py" ycmd-extra-conf-whitelist
                       '("~/project/*"))
                 lua python javascript react emacs-lisp csharp
                 (org :variables org-enable-github-support t)
                 latex markdown)
@TheBB
Copy link
Collaborator

TheBB commented Sep 12, 2016

I disagree that this is a bug. The most intuitive behaviour is that the private snippets supplant the base set, not replace them entirely. If you don't want the base set it's simple enough to remove it in your config already.

The desired behavior is:

  • If private-yas-dir (set by variable auto-completion-private-snippets-directory or generated from configuration-layer-private-directory) is found in file system, yas-installed-snippets-dir should be ignored.

Why would this be desired?

@hghwng
Copy link
Contributor Author

hghwng commented Sep 12, 2016

The most intuitive behaviour is that the private snippets supplant the base set, not replace them entirely.

I don't think people who want their snippets customized are likely to continue to use the base set.

For example, it's difficult to modify an existing snippet. I can't modify the file lying in the original directory, or it could possibly be overwritten by package updates. The only way to make it DWIM, is copy the existing snippets into the private snippet directory, and remove the base directory from yas-snippet-dirs. What's more, no support is provided by variables of the auto-completion layer; the only way is to adjust the list by hand.

Copy all the base snippets to the private directory, and adjust the variable by hand. It's too much for such a simple task.

I believe that all users of Spacemacs are power users, and of course they'd like to tweak their snippets to fit their own coding style and achieving more efficiency. The behavior that I proposed takes consider of all scenarios:

  • People who use the base snippets only.
  • People who want to customize the snippets. (Copy the snippets to private directory, and modify as you want)
  • People who like the current behavior of auto-completion. (Set auto-completion-enable-base-snippets to t)

@TheBB
Copy link
Collaborator

TheBB commented Sep 12, 2016

For example, it's difficult to modify an existing snippet. I can't modify the file lying in the original directory, or it could possibly be overwritten by package updates. The only way to make it DWIM, is copy the existing snippets into the private snippet directory, and remove the base directory from yas-snippet-dirs.

You could copy the existing snippet into the private directory, modify it, and not remove the base directory. Since the private directory comes first in yas-snippet-dirs, your modified snippet will be chosen. There's no need to explicitly remove the base set just because you want to change some of them. The only reason you'd want to do that is if you explicitly want fewer snippets, but I (being not a snippet power user) have never in my life felt that the snippets intrude on my coding, so I don't recognize that being an issue.

All your hypothetical users are well served by the current system, as far as I can see.

  • People who use the base snippets only.

should be satisfied with the current system.

  • People who want to customize the snippets. (Copy the snippets to private directory, and modify as you want)

should be satisfied by the current system. (I just did exactly this. It works.)

  • People who like the current behavior of auto-completion.

should be satisfied by the current system (by definition).

@hghwng
Copy link
Contributor Author

hghwng commented Sep 13, 2016

Since the private directory comes first in yas-snippet-dirs, your modified snippet will be chosen.

The default snippet set contains multiple snippets that binds to the same key. For example, both c++-mode/{ns, namespace} bind to ns. If you want to expand the snippet directly, instead of choosing one from the list inefficiently, you do want fewer snippets.

The only reason you'd want to do that is if you explicitly want fewer snippets

This is not the only reason I guess. More importantly, the behavior of current setting is not consistent. Let me explain:

  • To create a new snippet, yas-new-snippet creates the file in the private directly -- works as expected.
  • To modify a snippet, you can possibly lost the changes by SPC i s F2 (helm-yas), because it modifies the base snippets directly. You have to copy all base snippets to private directory, before happily edit them.
  • To remove a snippet (as the scenario described above), not only should you copy all base snippets, but also modify your .spacemacs configuration.

I really don't think the current behavior is desirable.

@hghwng
Copy link
Contributor Author

hghwng commented Sep 14, 2016

For consistent behavior, what about the following method? Ignore the basic snippets when private snippets are detected. On modification to basic snippets or creating new snippets, all snippets are copied to private directory immediately.

If you just use the basic set, everything works fine and snippets are automatically synchronized with elpa.
If you modify the basic set, you can customize it as you want. But there'll be no more updates.

@hghwng
Copy link
Contributor Author

hghwng commented Jun 8, 2017

It has been 9 months since the last update. I've found my own way to work around long ago. Should any user confuse about the behavior, I'd recommend ignoring what Spacemacs layers do for you, and configure yas-snippet-dirs manually:

  (setq yas-snippet-dirs '("~/.emacs.d/private/snippets"))

After reviewing the whole thread, I think it's time to archive this issue. However, closing the issue doesn't imply my satisfaction towards the current settings.

When many people use the software, maintaining backward compatibility is a burdensome must somehow. It's difficult to come up with a solution that takes care of all users. In conclusion, let's get over with it, and move on!

@hghwng hghwng closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Mailing list
  
Other
Development

No branches or pull requests

2 participants