Skip to content

Commit

Permalink
ivy.el (ivy-word-at-point-dwim): new function.
Browse files Browse the repository at this point in the history
counsel.el: use ivy-word-at-point-dwim as a default
for ivy-initial-inputs-alist for grep-like commands.
  • Loading branch information
mookid committed Dec 24, 2018
1 parent bbd9e6a commit 6d639de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -5048,6 +5048,12 @@ Local bindings (`counsel-mode-map'):
(when (fboundp 'advice-remove)
(advice-remove #'describe-bindings #'counsel-descbinds))))

(dolist (cmd ivy-highlight-grep-commands)
(add-to-list 'ivy-initial-inputs-alist
(cons cmd 'ivy-word-at-point-dwim)
nil
(lambda (cell1 cell2) (eq (car cell1) (car cell2)))))

(provide 'counsel)

;;; counsel.el ends here
14 changes: 14 additions & 0 deletions ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -4424,6 +4424,20 @@ EVENT gives the mouse position."
(expand-file-name "doc/ivy-help.org"))))
"The file for `ivy-help'.")

(defun ivy-word-at-point-dwim ()
"Extracts a meaningful part of the current buffer.
This function tries to DWIM. It either uses the beginning of the region if acivated, or the current word.
It is destined to be used as a cdr in `ivy-initial-inputs-alist'."
(cond ((and transient-mark-mode mark-active)
(let* ((beg (region-beginning))
(end (region-end))
(eol (save-excursion (goto-char beg) (line-end-position))))
(buffer-substring-no-properties beg (min end eol))))
(t
(current-word))))

(defun ivy-help ()
"Help for `ivy'."
(interactive)
Expand Down

0 comments on commit 6d639de

Please sign in to comment.