1

I am trying to be able to control where a new window should go, when I use helm-find-files. I am aware of split-height-threshold and split-width-threshold, and it works if I set them to behave appropriately (setq outside the defuns). But what I am trying to do is set them temporarily before calling the function that actually splits the window (here, helm-ff-run-switch-other-window). However, even though these 2 variables have the correct values (using let), the functions don't seem to do anything. Perhaps the code will explain it better:

(defun my/helm-switch-other-window-horizontally ()
  (interactive)
  (let ((split-height-threshold 0)
        (split-width-threshold nil))
    (helm-ff-run-switch-other-window)))


(defun my/helm-switch-other-window-vertically ()
  (interactive)
  (let ((split-height-threshold nil)
        (split-width-threshold 0))
    (helm-ff-run-switch-other-window)))

(define-key helm-find-files-map (kbd "C-c s") 'my/helm-switch-other-window-horizontally)
(define-key helm-find-files-map (kbd "C-c v") 'my/helm-switch-other-window-vertically)

I guess I'm doing something wrong with variable binding?

  • You can let-bind around helm-find-files-other-window instead, it looks like helm-ff-run-switch-other-window itself doesn't call split-window etc at all in its life cycle. It is possible by using run-at-time etc, for example. Though I don't know the internal of helm. – xuchunyang Feb 22 '17 at 12:50
0

The following is based on your own code, which works as expected from here.

(defun my/helm-switch-other-window-horizontally ()
  (interactive)
  (with-helm-alive-p
    (helm-exit-and-execute-action
     (lambda (candidate)
       (let ((split-height-threshold 0)
             (split-width-threshold nil))
         (helm-find-files-other-window candidate))))))

(defun my/helm-switch-other-window-vertically ()
  (interactive)
  (with-helm-alive-p
    (helm-exit-and-execute-action
     (lambda (candidate)
       (let ((split-height-threshold nil)
             (split-width-threshold 0))
         (helm-find-files-other-window candidate))))))

(define-key helm-find-files-map (kbd "C-c s") 'my/helm-switch-other-window-horizontally)
(define-key helm-find-files-map (kbd "C-c v") 'my/helm-switch-other-window-vertically)

I don't have answer on why your let-binding don't work since I am not familiar with the internal of helm. Maybe the following may provide a clue:

(defvar x nil)
(defun foo ()
  (message "-> %s" x))

(let ((x 42))
  (foo))
;; Print "-> 42"

(let ((x 42))
  (run-at-time nil nil 'foo))
;; Print "-> nil"

as you can see let-binding x doesn't work for run-at-time.

  • Yes! I was going towards this direction following the other comments. My general question is: since helm-ff-run-switch-other-window calls helm-find-files-other-window, why using let like I did have the same effect? Does it bind only up to a specific level in the call stack? – alexpeits Feb 22 '17 at 17:37
  • @alexpeits I don't know, but at least let-binding doesn't work for run-at-time, I have updated my answer for this. – xuchunyang Feb 23 '17 at 4:38
0

The variables in let can not be accessed by functions outside. setq-local split-height-threshold nil should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.