diff options
author | Ulrich Müller <ulm@gentoo.org> | 2017-01-15 19:45:40 +0100 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2017-01-15 19:45:40 +0100 |
commit | c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e (patch) | |
tree | 935785c5507a6b25f9c33e2ecd77539e175e77fd | |
parent | Update copyright years. (diff) | |
download | ebuild-mode-c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e.tar.gz ebuild-mode-c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e.tar.bz2 ebuild-mode-c3dd382167167a06ff2abd4b53ffbbd1a16a9e0e.zip |
Improve error handling when no KEYWORDS line is found.
* ebuild-mode.el (ebuild-mode-get-keywords)
(ebuild-mode-put-keywords): Improve error handling.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ebuild-mode.el | 40 |
2 files changed, 27 insertions, 18 deletions
@@ -1,3 +1,8 @@ +2017-01-15 Ulrich Müller <ulm@gentoo.org> + + * ebuild-mode.el (ebuild-mode-get-keywords) + (ebuild-mode-put-keywords): Improve error handling. + 2016-06-19 Ulrich Müller <ulm@gentoo.org> * 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." |