From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.devel Subject: [PATCH v2] lisp/progmodes/etags.el clean up code by removing a temporary Date: Tue, 19 Mar 2019 09:55:49 +0300 Message-ID: <20190319065549.16369-1-Hi-Angel@yandex.ru> References: <20190316015314.2335-1-Hi-Angel@yandex.ru> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="67300"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 19 07:56:26 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h68fh-000HSK-Bq for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2019 07:56:25 +0100 Original-Received: from localhost ([127.0.0.1]:52559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h68fg-00023F-Df for ged-emacs-devel@m.gmane.org; Tue, 19 Mar 2019 02:56:24 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h68fY-00023A-St for emacs-devel@gnu.org; Tue, 19 Mar 2019 02:56:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h68fY-0006oW-0j for emacs-devel@gnu.org; Tue, 19 Mar 2019 02:56:16 -0400 Original-Received: from forward105o.mail.yandex.net ([2a02:6b8:0:1a2d::608]:34586) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h68fW-0006gM-WD for emacs-devel@gnu.org; Tue, 19 Mar 2019 02:56:15 -0400 Original-Received: from mxback3o.mail.yandex.net (mxback3o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1d]) by forward105o.mail.yandex.net (Yandex) with ESMTP id 16D704201EC5 for ; Tue, 19 Mar 2019 09:56:08 +0300 (MSK) Original-Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback3o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id PxY4eLhAkG-u8kSwWhR; Tue, 19 Mar 2019 09:56:08 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1552978568; bh=TVC+QxYpT2dyTHkxti2l76pHQwTa1gjUV5cFT2Yu7OY=; h=In-Reply-To:Subject:To:From:References:Date:Message-Id; b=BG4expR/mBXFSrh+T39NCA0OzyPodQPqiv9d+6pS9Kufk6ebq79G0k9hKC/RyJAAB xrUJZcMt+dn4t8YcyCHrjUcRs7CiFvVmEO4jYNHfVIH6HVDNNJZjpeMlyal3KbqTT3 fVzBJY3gVzQR6i8HeomEPdRGea9bRY4mefMo1aVU= Authentication-Results: mxback3o.mail.yandex.net; dkim=pass header.i=@yandex.ru Original-Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id w99tXkKGsp-u1k4HlYx; Tue, 19 Mar 2019 09:56:01 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190316015314.2335-1-Hi-Angel@yandex.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:6b8:0:1a2d::608 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:234356 Archived-At: --- 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. --=20 2.21.0