[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] lisp/progmodes/etags.el clean up code by removing a temporary
From: |
Konstantin Kharlamov |
Subject: |
[PATCH v2] lisp/progmodes/etags.el clean up code by removing a temporary |
Date: |
Tue, 19 Mar 2019 09:55:49 +0300 |
---
v2: I fixed a bug that I didn't return t from "while". The code does not
look as short now as I'd hoped for; it's a little less of the original
size. But I think it's still might be useful, because it refactors the
code to have the relevant functional closer, and removes a variable from
function's visibility scope.
lisp/progmodes/etags.el | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index c2715be5370..0014c10eb81 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -1351,7 +1351,7 @@ etags-goto-tag-location
hits the start of file."
(let ((startpos (cdr (cdr tag-info)))
(line (car (cdr tag-info)))
- offset found pat)
+ offset pat)
(if (eq (car tag-info) t)
;; Direct file tag.
(cond (line (progn (goto-char (point-min))
@@ -1363,7 +1363,6 @@ etags-goto-tag-location
;; since just going around the loop once probably
;; costs about as much as searching 2000 chars.
(setq offset 1000
- found nil
pat (concat (if (eq selective-display t)
"\\(^\\|\^m\\)" "^")
(regexp-quote (car tag-info))))
@@ -1385,19 +1384,19 @@ etags-goto-tag-location
(point)))))
(or startpos
(setq startpos (point-min)))
- ;; First see if the tag is right at the specified location.
(goto-char startpos)
- (setq found (looking-at pat))
- (while (and (not found)
- (progn
- (goto-char (- startpos offset))
- (not (bobp))))
- (setq found
- (re-search-forward pat (+ startpos offset) t)
- offset (* 3 offset))) ; expand search window
- (or found
- (re-search-forward pat nil t)
- (user-error "Rerun etags: `%s' not found in %s"
+ (or (looking-at pat) ; Is tag at the specified location?
+ (catch 'found
+ (while (progn
+ (goto-char (- startpos offset))
+ (when (bobp)
+ (throw 'found nil))
+ (when (re-search-forward pat (+ startpos offset) t)
+ (throw 'found t))
+ t)
+ (setq offset (* 3 offset)))) ; expand search window
+ (re-search-forward pat nil t)
+ (user-error "Rerun etags: `%s' not found in %s"
pat buffer-file-name)))
;; Position point at the right place
;; if the search string matched an extra Ctrl-m at the beginning.
--
2.21.0
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, (continued)
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Konstantin Kharlamov, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Eli Zaretskii, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Konstantin Kharlamov, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Konstantin Kharlamov, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Eli Zaretskii, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Konstantin Kharlamov, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Konstantin Kharlamov, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Konstantin Kharlamov, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Stefan Monnier, 2019/03/18
- Re: [PATCH 2/3] lisp/progmodes/etags.el don't (forward-char) as it's overriden next line, Eli Zaretskii, 2019/03/19
[PATCH v2] lisp/progmodes/etags.el clean up code by removing a temporary,
Konstantin Kharlamov <=