Skip to content

Instantly share code, notes, and snippets.

@arielshaqed
Created January 11, 2018 13:16
Show Gist options
  • Save arielshaqed/5f31850039fa62b7eda6603b24cd0bf6 to your computer and use it in GitHub Desktop.
Save arielshaqed/5f31850039fa62b7eda6603b24cd0bf6 to your computer and use it in GitHub Desktop.
Emacs: helm commands with other-window defaults
;;; Versions of helm commands that usefully replace `find-file-other-window'
;;; and `switch-to-buffer-other-window'. They work by replacing the default
;;; action and calling the actual helm functions.
(defun as-alist-move-cdr-first (alist cdr-value)
"Returns a copy of alist, but with the (first) element with CDR cdr-value at its head."
(let ((first (rassoc cdr-value alist)))
(if first
(cons first (map-remove #'(lambda (key value) (equal value cdr-value)) alist))
alist)))
;; Bind this to [C-x 4 C-f].
(defun as-helm-ff-other-window (arg)
"`helm-find-files' with a default action for `find-file-other-window'."
(interactive "P")
(let ((helm-find-files-actions
(as-alist-move-cdr-first helm-find-files-actions 'helm-find-files-other-window)))
(helm-find-files arg)))
;; Bind this to [C-x 4 b]
(defun as-helm-mini-other-window nil
"`helm-mini' with a default action for buffers to use other window."
(interactive)
(let ((helm-type-buffer-actions
(as-alist-move-cdr-first helm-type-buffer-actions 'helm-buffer-switch-buffers-other-window)))
(helm-mini)))
@arielshaqed
Copy link
Author

arielshaqed commented Jan 11, 2018

New to helm?

Keep on hitting C-x 4 f, C-x 4 b?

Me too! Instead of training my fingers, I decided to train Emacs. After binding keys to these 2 commands, I get to ...-other-window whenever I like. It just works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment