emacsorphanage / helm-swoop

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

Calling helm-swoop-yank-word multiple times #90

Closed jeberger closed 5 years ago

jeberger commented 8 years ago

Hi, currently assuming I have this text in the buffer when I invoke helm-swoop: f|oo bar (| marks the position of the cursor), then when I hit C-w several times, it appends foo to the search pattern each time. I.e, assuming that I started with an empty search pattern, I get:

I would like a behaviour closer to that of the default isearch function (or helm-yank-text-at-point), i.e I would like to get:

Thanks.

lynnux commented 7 years ago

Try this, it's combined ivy-yank-word and helm-swoop-yank-thing-at-point, but has a side effect that changed the helm-swoop-last-point:

(defun my-helm-swoop-yank-thing-at-point ()
    "Insert string at which the point helm-swoop started."
    (interactive)
    (let ($amend $buf)
      (with-selected-window helm-swoop-synchronizing-window
        (setq $buf (get-buffer (cdr helm-swoop-last-point)))
        (when $buf
          (with-current-buffer $buf
        (goto-char (car helm-swoop-last-point))
        (let ((pt (point))
              (le (line-end-position)))
          (forward-word 1)
          (if (> (point) le)
              (goto-char pt)
            (setq $amend (buffer-substring-no-properties pt (point)))))
        (setcar helm-swoop-last-point (point))
        )))
      (when $amend
        (with-selected-window (minibuffer-window)
          (insert $amend)))))

(with-eval-after-load 'helm-swoop
    (define-key helm-swoop-map (kbd "C-w") 'my-helm-swoop-yank-thing-at-point))

however, the cursor not function OK.

sfavazza commented 5 years ago

I just recently bumped into the same issue. I liked the idea to add symbols to the search strings instead of yanking words.

You might try also this code below, to advice the original helm-swoop-yank-thing-at-point to update its point after each call:


;; forward the pointer instead to yank the same symbol over and over
(defun custom-helm-to-next-symbol ()
  ;; ensure separation between two consecutive symbols
  (insert " ")
  ;; move pointer to next symbol in last buffer
  (with-selected-window helm-swoop-synchronizing-window
    (with-current-buffer (get-buffer (cdr helm-swoop-last-point))
      (goto-char (car helm-swoop-last-point))
      (forward-symbol 1)
      ;; update the last point value
      ;; NOTE: this must be done here, otherwise once out of the buffer context the point
      ;; is reset to the beginning of the line.
      (setcar helm-swoop-last-point (point))))
  )
;; advice the yank function with the custom function
(advice-add 'helm-swoop-yank-thing-at-point :before #'custom-helm-to-next-symbol)```
jeberger commented 5 years ago

Hitting C-w no longer works at all. However, I get the effect I want with M-j, which is provided by swiper