Open showgood opened 6 years ago
I looked at the yasnippet
code and it was pretty complex. I agree that it would be a nice feature though, so I'll see if I can add it in the future. I modified yankpad-expand
so that it can be used by hippie-expand
. Not sure if you use hippie-expand
, but if you do then you won't need an extra key for yankpad-expand
.
thanks! would be nice to see Tab works in the future.
Just to let you guys know I did a little testing if you download the package "smart-tab" from melpa and add:
(require 'yankpad)
(require 'smart-tab)
(setq smart-tab-using-hippie-expand t)
(add-to-list 'hippie-expand-try-functions-list #'yankpad-expand)
(global-smart-tab-mode 1)
You get almost the same functionality as yasnippet (you actually get more functionally as you get hippie expand as well). This could be a pro or a con depending on how you use hippie-expand
.
However I also wrote something that I believe emulates yasnippet behavior, I have no clue if this is the correct way, but for those who want to keep hippie separate from tab:
(require 'yankpad)
(defun yankpad-maybe-expand ()
"First tries to expand word at point. If it fails it looks up
the major mode keypress for tab, and then the global key map."
(interactive)
(when (equal nil (yankpad-expand))
(if (lookup-key (current-local-map) (kbd "TAB"))
(call-interactively (lookup-key (current-local-map) (kbd "TAB")))
(call-interactively (lookup-key (current-global-map) (kbd "TAB"))))))
(defvar yankpad-expand-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "TAB") 'yankpad-maybe-expand)
(define-key map (kbd "<tab>") 'yankpad-maybe-expand)
(define-key map (kbd "\C-i") 'yankpad-maybe-expand)
map))
(define-minor-mode yankpad-expand-mode
"A mode that first tries to `yankpad-expand' and then if it fails
look up the major mode keypress for tab, and then if that doesn't
exist look up the global keypress for tab."
:lighter nil
:keymap yankpad-expand-mode-map)
(defun yankpad-expand-mode-on ()
"Turns on `yankpad-expand-mode'."
(interactive)
(yankpad-expand-mode 1))
(define-global-minor-mode global-yankpad-expand-mode yankpad-expand-mode yankpad-expand-mode-on)
To activate just call (global-yankpad-expand-mode 1)
.
@phoenixanimations Looks nice! I'll try yankpad-maybe-expand
and the minor-mode. If it works nicely, I'll add it to yankpad
. I hope that's okay?
Ya of course :) ty for this package.
I use smart-tab
as @phoenixanimations suggested but as that doesn't work for org-mode I added yankpad-expand
to org-tab-after-check-for-cycling-hook
, and that works pretty good!
I like the idea of yankpad and trying to migrate to it from yasnippet.
but later I realized if I simply bind to
yankpad-expand
, then tab will stop working in org mode for things like create tab, folding etc.yasnippet has something call for completion
doesn't conflict with anything else and I really like to use for yankpad expand,
however I haven't find out how to achieve that.
yas-maybe-expand
can bindplease help, thanks.