emacsorphanage / helm-swoop

Efficiently hopping squeezed lines powered by Emacs helm interface
GNU General Public License v3.0
689 stars 55 forks source link

Improve helm-swoop about helm-swoop-pre-input-function #54

Closed c02y closed 9 years ago

c02y commented 9 years ago

I know many people have already posted several issues about helm-swoop-pre-input-function and you also mentioned it at Configure pre-input search query part in README.md file , but I request a new solution about it.

When invoking helm-swoop, by default, it could be empty in the input part (so I can type string/regexp I want to search later), when typing C-s at this status (with empty in the input part), the string/thing-at-point/... will be put into the input part and show the occurs instantly.

ShingoFukuyama commented 9 years ago

If I understand your intention correctly, this could be done :fish_cake::

(defun my-helm-swoop-after-input ($query)
  (interactive "sInput Query: ")
  (helm-swoop :$query $query))

(global-set-key (kbd "M-i") 'my-helm-swoop-after-input)
c02y commented 9 years ago

No, it doesn't work, besides, I cannot even quit the action using C-g

ShingoFukuyama commented 9 years ago

Sorry for misunderstanding. How about this?:

(setq helm-swoop-pre-input-function (lambda () ""))

(defun my-helm-swoop-move-line-with-string-at-point-if-needed ($move-fn)
  (if (equal helm-swoop-pattern "")
      (let (($string ""))
        (with-current-buffer (get-buffer-create (cdr helm-swoop-last-point))
          (save-excursion
            (goto-char (car helm-swoop-last-point))
            (setq $string (thing-at-point 'symbol))))
        (with-selected-window (or (active-minibuffer-window)
                                  (minibuffer-window))
          (insert $string)))
    (call-interactively $move-fn)))

(defun my-helm-swoop-next-line-with-string-at-point-if-needed ()
  (interactive)
  (my-helm-swoop-move-line-with-string-at-point-if-needed 'helm-next-line))
(defun my-helm-swoop-prev-line-with-string-at-point-if-needed ()
  (interactive)
  (my-helm-swoop-move-line-with-string-at-point-if-needed 'helm-previous-line))

(define-key helm-swoop-map (kbd "C-s") 'my-helm-swoop-next-line-with-string-at-point-if-needed)
(define-key helm-swoop-map (kbd "C-r") 'my-helm-swoop-prev-line-with-string-at-point-if-needed)