Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for disabling line number matching #184

Merged
merged 3 commits into from
May 15, 2020

Conversation

palikar
Copy link
Contributor

@palikar palikar commented May 14, 2020

This change should improve the use experience of searching for numbers in a buffer. The added custom variable also allows for enabling the previous behavior of matching the line number as a number.

The change addresses directly #157 and #45.

helm-swoop.el Outdated Show resolved Hide resolved
@cireu
Copy link
Collaborator

cireu commented May 14, 2020

I think we can replace magic caret with new match-part based mechanism @conao3

diff --git a/helm-swoop.el b/helm-swoop.el
index b5374c3..c0a5efb 100644
--- a/helm-swoop.el
+++ b/helm-swoop.el
@@ -184,11 +184,6 @@ If value is symbol `always', always do fontify."
           integer
           (const :tag "Always Fontify" always)))
 
-(defcustom helm-swoop-exclude-matching-linenums t
-  "If non-nil, exclude the linu numbers while mathcing the input pattern."
-  :group 'helm-swoop
-  :type 'boolean)
-
 (defvar helm-swoop-candidate-number-limit 19999)
 (defvar helm-swoop-buffer "*Helm Swoop*")
 (defvar helm-swoop-prompt "Swoop: ")
@@ -233,7 +228,6 @@ If value is symbol `always', always do fontify."
     (define-key map (kbd "C-c C-e") 'helm-swoop-edit)
     (define-key map (kbd "M-i") 'helm-multi-swoop-all-from-helm-swoop)
     (define-key map (kbd "C-w") 'helm-swoop-yank-thing-at-point)
-    (define-key map (kbd "^") 'helm-swoop-caret-match)
     map)
   "Keymap for helm-swoop.")
 
@@ -580,10 +574,7 @@ This function needs to call after latest helm-swoop-line-overlay set."
 
 (defun helm-swoop--match-part (candidate)
   "Extract the proper part of CANDIDATE."
-  (if (and helm-swoop-exclude-matching-linenums
-           (string-match (rx bol (+? digit) " ") candidate))
-      (replace-match "" 'nil 'nil candidate)
-    candidate))
+  (replace-regexp-in-string (rx bol (+? digit) " ") "" candidate))
 
 (defun helm-swoop--maybe-fontify! ()
   "Ensure the entired buffer is highlighted."
@@ -871,43 +862,6 @@ If LINUM is number, lines are separated by LINUM."
         (let ((helm-last-buffer (cadr helm-buffers))) ad-do-it))
     ad-do-it))
 
-;; For caret beginning-match -----------------------------
-(defun helm-swoop--caret-match-delete (ov aft beg end &optional len)
-  "Caret match delete for OV, AFT in BEG to END and LEN."
-  (if aft
-      (- end beg len) ;; Unused argument? To avoid byte compile error
-    (delete-region (overlay-start ov) (1- (overlay-end ov)))))
-
-(defun helm-swoop-caret-match (&optional _resume)
-  "Caret match."
-  (interactive)
-  (let* ((prompt helm-swoop-prompt) ;; Accept change of the variable
-         (line-number-regexp "^[0-9]+.")
-         (prompt-regexp
-          (funcall `(lambda ()
-                      (rx bol ,prompt))))
-         (prompt-regexp-with-line-number
-          (funcall `(lambda ()
-                      (rx bol ,prompt (group ,line-number-regexp)))))
-         (disguise-caret
-          (lambda ()
-            (save-excursion
-              (re-search-backward prompt-regexp-with-line-number nil t)
-              (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
-                (overlay-put ov 'face 'helm-swoop-target-word-face)
-                (overlay-put ov 'modification-hooks '(helm-swoop--caret-match-delete))
-                (overlay-put ov 'display "^")
-                (overlay-put ov 'evaporate t))))))
-    (if (and (minibufferp)
-             (string-match prompt-regexp
-                           (buffer-substring-no-properties
-                            (point-min) (point-max)))
-             (eq (point) (+ 1 (length helm-swoop-prompt))))
-        (progn
-          (insert line-number-regexp)
-          (funcall disguise-caret))
-      (insert "^"))))
-
 ;;; @ helm-swoop-edit -----------------------------------------
 
 (defvar helm-swoop-edit-target-buffer)

@conao3
Copy link
Collaborator

conao3 commented May 14, 2020

LGTM.

@cireu cireu merged commit 493e145 into emacsorphanage:master May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants