fancy-dabbrev
fancy-dabbrev copied to clipboard
Add minor mode keymap so that tab & shift-tab are bound by default when fancy-dabbrev is active.
Hi thanks for writing this, I was using pabbrev before and this is much better.
The only annoyance I found so far is that setting the global "TAB" key doesnt work in a lot of modes since its often used for language specific indentation and other features. (I did notice #14 and another issue related to org mode which seem to be similar).
I lifted some code from pabbrev and patched fancy-dabbrev.el to fix this:
diff --git fancy-dabbrev.el fancy-dabbrev.el
index be7e1914f4b5351a3d3974f37024bbecbf905ebb..cfea313bd095aab5f3aafbbbeae16b3ea9eedf4a 100644
--- fancy-dabbrev.el
+++ fancy-dabbrev.el
@@ -614,6 +614,21 @@ That is, if `this-command' is not one of
(when (fancy-dabbrev--is-fancy-dabbrev-command last-command)
(fancy-dabbrev--insert-expansion fancy-dabbrev--entered-abbrev)))
+;; Pierre: This should do the basic to hook tab & shift-tab to
+;; fancy-dabbrev-expand. This is lifted from pabbrev, that mode also keep
+;; track of the previous binding to tab and call it, I assume when there's no
+;; expansion, which is probably ideal but its a fair bit of code I dont
+;; understand and this is all I need for now.
+(defvar fancy-dabbrev-mode-map
+ (let ((map (make-sparse-keymap)))
+ ;; \t works in tty but gets overridden by the [tab] binding elsewhere.
+ (define-key map "\t" 'fancy-dabbrev-expand-or-indent)
+ ;; This is not needed since function-key-map remaps a `tab' into a \t.
+ ;; (define-key map (kbd "TAB") 'fancy-dabbrev-expand)
+ (define-key map (kbd "<backtab>") 'fancy-dabbrev-backward)
+ map)
+ "Keymap for fancy-dabbrev-minor-mode.")
+
;;;###autoload
(define-minor-mode fancy-dabbrev-mode
"Toggle `fancy-dabbrev-mode'.
@@ -624,6 +639,7 @@ the mode if ARG is omitted or nil.
When `fancy-dabbrev-mode' is enabled, fancy-dabbrev's preview
functionality is activated."
+ :keymap fancy-dabbrev-mode-map
:lighter " FD"
:init-value nil
(if fancy-dabbrev-mode
There's probably a more configurable way to do this but this is good enough for my use cases, hopefully this is helpful for others.