Last active
February 12, 2022 09:04
-
-
Save tam17aki/f5046e9381436e783df385b42b11125b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; consult-thing-at-point.el --- Consult extension for thing-at-point -*- | |
;; Copyright (C) 2015-2021 Free Software Foundation, Inc. | |
;; Copyright (C) 2022 ballforest | |
;; This file is free software; you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation; either version 3, or (at your option) | |
;; any later version. | |
;; This program is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; For a full copy of the GNU General Public License | |
;; see <https://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; Inspried by `ivy-thing-at-point' and `swiper-thing-at-point', | |
;; this package provides the `consult' alternative. | |
;;; Code: | |
(require 'consult) | |
(defun consult-thing-at-point () | |
"Return a string that corresponds to the current thing at point." | |
(substring-no-properties | |
(cond | |
((use-region-p) | |
(let* ((beg (region-beginning)) | |
(end (region-end)) | |
(eol (save-excursion (goto-char beg) (line-end-position)))) | |
(buffer-substring-no-properties beg (min end eol)))) | |
((thing-at-point 'url)) | |
((let ((s (thing-at-point 'symbol))) | |
(and (stringp s) | |
(if (string-match "\\`[`']?\\(.*?\\)'?\\'" s) | |
(match-string 1 s) | |
s)))) | |
((looking-at "(+\\(\\(?:\\sw\\|\\s_\\)+\\)\\_>") | |
(match-string-no-properties 1)) | |
(t | |
"")))) | |
;;;###autoload | |
(defun consult-line-thing-at-point () | |
"`consult-line' with `consult-thing-at-point'." | |
(interactive) | |
(let ((thing (consult-thing-at-point))) | |
(when (use-region-p) | |
(deactivate-mark)) | |
(consult-line (regexp-quote thing)))) | |
(provide 'consult-thing-at-point) | |
;;; consult-thing-at-point.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment