From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 4CAC1139694 for ; Tue, 28 Feb 2017 19:24:01 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 39898E0D27; Tue, 28 Feb 2017 19:23:09 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0CD70E0D27 for ; Tue, 28 Feb 2017 19:23:09 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0100834164C for ; Tue, 28 Feb 2017 19:23:08 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0636D57D4 for ; Tue, 28 Feb 2017 19:23:06 +0000 (UTC) From: "Ulrich Müller" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" Message-ID: <1484505940.c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e.ulm@gentoo> Subject: [gentoo-commits] proj/emacs-tools:ebuild-mode commit in: / X-VCS-Repository: proj/emacs-tools X-VCS-Files: ChangeLog ebuild-mode.el X-VCS-Directories: / X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e X-VCS-Branch: ebuild-mode Date: Tue, 28 Feb 2017 19:23:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: b24046be-08c3-4e0d-a89e-ca93db12f16e X-Archives-Hash: 89a42a0a396979f813410a7507a99fae commit: c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e Author: Ulrich Müller gentoo org> AuthorDate: Sun Jan 15 18:45:40 2017 +0000 Commit: Ulrich Müller gentoo org> CommitDate: Sun Jan 15 18:45:40 2017 +0000 URL: https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=c3dd3821 Improve error handling when no KEYWORDS line is found. * ebuild-mode.el (ebuild-mode-get-keywords) (ebuild-mode-put-keywords): Improve error handling. ChangeLog | 5 +++++ ebuild-mode.el | 40 ++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a98fb3..a28c4c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-01-15 Ulrich Müller + + * ebuild-mode.el (ebuild-mode-get-keywords) + (ebuild-mode-put-keywords): Improve error handling. + 2016-06-19 Ulrich Müller * Version 1.31 released. diff --git a/ebuild-mode.el b/ebuild-mode.el index a088db6..5ccc63d 100644 --- a/ebuild-mode.el +++ b/ebuild-mode.el @@ -269,29 +269,33 @@ Optional argument LIMIT restarts collection after that number of elements." (save-excursion (goto-char (point-min)) (let ((case-fold-search nil)) - (and (re-search-forward ebuild-mode-arch-regexp nil noerror) - (not (and (re-search-forward ebuild-mode-arch-regexp nil t) - (or noerror - (error "More than one KEYWORDS assignment found")))) - (mapcar (lambda (s) - (string-match "^\\([-~]?\\)\\(.*\\)" s) - (cons (match-string 2 s) (match-string 1 s))) - (split-string - ;;(match-string-no-properties 1) ; not in XEmacs 21.4 - (buffer-substring-no-properties (match-beginning 1) - (match-end 1)))))))) + (cond + ((not (re-search-forward ebuild-mode-arch-regexp nil t)) + (unless noerror (error "No KEYWORDS assignment found"))) + ((re-search-forward ebuild-mode-arch-regexp nil t) ; second search + (unless noerror (error "More than one KEYWORDS assignment found"))) + (t + (mapcar (lambda (s) + (string-match "^\\([-~]?\\)\\(.*\\)" s) + (cons (match-string 2 s) (match-string 1 s))) + (split-string + ;;(match-string-no-properties 1) ; not in XEmacs 21.4 + (buffer-substring-no-properties (match-beginning 1) + (match-end 1))))))))) (defun ebuild-mode-put-keywords (kw &optional noerror) (save-excursion (goto-char (point-min)) (let ((case-fold-search nil)) - (and (re-search-forward ebuild-mode-arch-regexp nil noerror) - (not (and (re-search-forward ebuild-mode-arch-regexp nil t) - (or noerror - (error "More than one KEYWORDS assignment found")))) - (replace-match - (mapconcat (lambda (e) (concat (cdr e) (car e))) kw " ") - t t nil 1))))) + (cond + ((not (re-search-forward ebuild-mode-arch-regexp nil t)) + (unless noerror (error "No KEYWORDS assignment found"))) + ((re-search-forward ebuild-mode-arch-regexp nil t) + (unless noerror (error "More than one KEYWORDS assignment found"))) + (t + (replace-match + (mapconcat (lambda (e) (concat (cdr e) (car e))) kw " ") + t t nil 1)))))) (defun ebuild-mode-modify-keywords (kw) "Set keywords. KW is an alist of architectures and leaders."