Closed jeberger closed 5 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.
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)```
Hitting C-w
no longer works at all. However, I get the effect I want with M-j
, which is provided by swiper
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 hitC-w
several times, it appendsfoo
to the search pattern each time. I.e, assuming that I started with an empty search pattern, I get:foo
the first time,foofoo
the second time,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:oo
the first time,oo bar
the second time,Thanks.