diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2014-05-03 07:01:37 +0200 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2014-05-03 07:01:37 +0200 |
commit | c993f4824bf09a126a0f7b9c8391bb3438ec1fc2 (patch) | |
tree | caa5612971efedb82ec66f7e9fcc9852777346d7 | |
parent | 9b8a67f1e0287196a7f37d91b28d2df7bb2d1bd3 (diff) |
* helm.el (helm-define-key-with-subkeys): New macro.
* helm-files.el: Use it to bind new function helm-ff-delete-char-backward.
(helm-ff-delete-char-backward,
helm-ff-delete-char-backward--exit-fn): new.
-rw-r--r-- | helm-files.el | 13 | ||||
-rw-r--r-- | helm-help.el | 4 | ||||
-rw-r--r-- | helm.el | 44 |
3 files changed, 58 insertions, 3 deletions
diff --git a/helm-files.el b/helm-files.el index 23500a33..8b52852e 100644 --- a/helm-files.el +++ b/helm-files.el @@ -327,6 +327,8 @@ WARNING: Setting this to nil is unsafe and can cause deletion of a whole tree." (define-key map (kbd "C-h C-b") 'helm-send-bug-report-from-helm) (define-key map (kbd "C-x @") 'helm-ff-run-find-file-as-root) (define-key map (kbd "C-c @") 'helm-ff-run-insert-org-link) + (helm-define-key-with-subkeys map (kbd "DEL") ?\d 'helm-ff-delete-char-backward + nil nil 'helm-ff-delete-char-backward--exit-fn) (when helm-ff-lynx-style-map (define-key map (kbd "<left>") 'helm-find-files-down-one-level) (define-key map (kbd "<right>") 'helm-execute-persistent-action)) @@ -824,6 +826,17 @@ See `helm-ff-serial-rename-1'." (helm-attrset 'toggle-auto-update '(helm-ff-toggle-auto-update . never-split)) (helm-execute-persistent-action 'toggle-auto-update))) +(defun helm-ff-delete-char-backward () + "Disable helm find files auto update and delete char backward." + (interactive) + (setq helm-ff-auto-update-flag nil) + (call-interactively + (lookup-key (current-global-map) + (read-kbd-macro "DEL")))) + +(defun helm-ff-delete-char-backward--exit-fn () + (setq helm-ff-auto-update-flag helm-ff-auto-update-initial-value)) + (defun helm-ff-run-switch-to-history () "Run Switch to history action from `helm-source-find-files'." (interactive) diff --git a/helm-help.el b/helm-help.el index 713c2e79..440490b0 100644 --- a/helm-help.el +++ b/helm-help.el @@ -272,9 +272,7 @@ Italic => A non--file buffer. You can also use `helm-follow-action-forward' and `helm-follow-action-backward' (`C-<down' and `C-<left>'). -- When you want to delete backward characters to e.g creating a new file or directory, - autoupdate may keep updating to an existent directory - preventing you to do so, in this case just hit C-<backspace> and then <backspace>. +- You can turn off/on (toggle) autoupdate completion at any moment with `C-DEL'. NOTE: On a terminal C-<backspace> may not work, use in this case C-c <backspace>. - You can create a new directory and a new file at the same time, just write the path in prompt @@ -109,6 +109,50 @@ First call run `helm-toggle-resplit-window', second call within 0.5s run `helm-swap-windows'." '(helm-toggle-resplit-window helm-swap-windows) 1) +(defmacro helm-define-key-with-subkeys (map key subkey command &optional other-subkeys menu exit-fn) + "Allow defining a KEY without having to type its prefix again on next calls. +Arg MAP is the keymap to use, SUBKEY is the initial long keybinding to +call COMMAND. +Arg OTHER-SUBKEYS is an unquoted alist specifying other short keybindings +to use once started. +e.g: + +\(helm-define-key-with-subkeys global-map + \(kbd \"C-x v n\") ?n 'git-gutter:next-hunk ((?p 'git-gutter:previous-hunk))\) + + +In this example, `C-x v n' will run `git-gutter:next-hunk' subsequent hit on \"n\" +will run this command again and subsequent hit on \"p\" will run `git-gutter:previous-hunk'. + +Arg MENU is a string to display in minibuffer to describe SUBKEY and OTHER-SUBKEYS. +Arg EXIT-FN specify a function to run on exit. + +Any other keys pressed run their assigned command defined in MAP and exit the loop." + + (let ((other-keys (and other-subkeys + (cl-loop for (x . y) in other-subkeys + collect (list x (list 'call-interactively y) t))))) + `(define-key ,map ,key + #'(lambda () + (interactive) + (unwind-protect + (progn + (call-interactively ,command) + (while (let ((input (read-key ,menu)) kb com) + (cl-case input + (,subkey (call-interactively ,command) t) + ,@other-keys + (t (setq kb (this-command-keys-vector)) + (setq com (lookup-key ,map kb)) + (if (commandp com) + (call-interactively com) + (setq unread-command-events + (nconc (mapcar 'identity + (this-single-command-raw-keys)) + unread-command-events))) + nil))))) + (funcall ,exit-fn)))))) + ;;; Keymap ;; |