1

Following up on a recent question of mine (here), I would like helm-swoop to behave in a certain way when pressing C-s that parallels the behaviour of isearch:

  1. C-s in a buffer: open helm-swoop with empty search field.
  2. C-s in helm-swoop with empty search field: activate previous search.
  3. C-s in helm-swoop with non-empty search field: go to next match.

The tricky parts are 2. and 3. obviously. Any suggestions?

1

The following works for me:

;; C-s in a buffer: open helm-swoop with empty search field
(global-set-key (kbd "C-s") 'helm-swoop)
(with-eval-after-load 'helm-swoop
    (setq helm-swoop-pre-input-function
        (lambda () nil)))

;; C-s in helm-swoop with empty search field: activate previous search.
;; C-s in helm-swoop with non-empty search field: go to next match.
(with-eval-after-load 'helm-swoop
    (define-key helm-swoop-map (kbd "C-s") 'tl/helm-swoop-C-s))

(defun tl/helm-swoop-C-s ()
    (interactive)
    (if (boundp 'helm-swoop-pattern)
            (if (equal helm-swoop-pattern "")
                    (previous-history-element 1)
                (helm-next-line))
    (helm-next-line)
    ))

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.