[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 206/352: Käsitellään oikolukuehdotusten virheet toisella tavalla
From: |
Stefan Monnier |
Subject: |
[elpa] 206/352: Käsitellään oikolukuehdotusten virheet toisella tavalla |
Date: |
Mon, 07 Jul 2014 14:04:08 +0000 |
monnier pushed a commit to branch master
in repository elpa.
commit b5d644034c11018cdcbf5e64c54c4d373c0c5750
Author: Teemu Likonen <address@hidden>
Date: Sun Jan 2 10:44:22 2011 +0000
Käsitellään oikolukuehdotusten virheet toisella tavalla
Käytetään Emacsin condition-case-rakennetta virheiden käsittelyyn.
Esimerkiksi oikolukuehdotusohjelma palautti aiemmin symbolin "error",
jos sen toiminnassa tuli virhe. Nyt se lähettää signaalin
wcheck-suggestion-program-error, joka sitten käsitellään kutsuvassa
funktiossa.
---
wcheck-mode.el | 85 +++++++++++++++++++++++++++++++++-----------------------
1 files changed, 50 insertions(+), 35 deletions(-)
diff --git a/wcheck-mode.el b/wcheck-mode.el
index b8d788c..ff10aee 100644
--- a/wcheck-mode.el
+++ b/wcheck-mode.el
@@ -1217,6 +1217,16 @@ the text and (3) marker at the end of the text."
start end)))))
+(wcheck-define-condition
+ wcheck-suggestion-error
+ '(error wcheck-suggestion-error))
+
+(wcheck-define-condition
+ wcheck-suggestion-program-error
+ '(error wcheck-suggestion-error
+ wcheck-suggestion-program-error))
+
+
;;;###autoload
(defun wcheck-spelling-suggestions (pos &optional event)
"Offer spelling suggestions for marked text.
@@ -1240,34 +1250,38 @@ Function returns the replacement text (string) or nil
if nothing
was replaced."
(interactive "d")
- (let ((overlay-data (or (wcheck-marked-text-at pos)
- (wcheck-marked-text-at (1- pos))))
- (return-value nil))
- (if overlay-data
- (let* ((text (aref overlay-data 0))
- (start (aref overlay-data 1))
- (end (aref overlay-data 2))
- (suggestions (wcheck-get-suggestions wcheck-language text)))
- (unless (eq suggestions 'error)
- (let ((choice (if (and (display-popup-menus-p) event)
- (wcheck-choose-suggestion-popup
- suggestions event)
- (wcheck-choose-suggestion-minibuffer
- suggestions))))
- (when (and (stringp choice)
- (markerp start)
- (markerp end))
- (with-current-buffer (marker-buffer start)
- (if buffer-read-only
- (message "Buffer is read-only")
- (delete-region start end)
- (goto-char start)
- (insert choice)
- (setq return-value choice))))))
- (if (markerp start) (set-marker start nil))
- (if (markerp end) (set-marker end nil)))
- (message "There is no marked text here"))
- return-value))
+ (condition-case error-data
+ (let ((overlay-data (or (wcheck-marked-text-at pos)
+ (wcheck-marked-text-at (1- pos))))
+ (return-value nil))
+ (if (not overlay-data)
+ (signal 'wcheck-suggestion-error
+ "There is no marked text here")
+ (let* ((text (aref overlay-data 0))
+ (start (aref overlay-data 1))
+ (end (aref overlay-data 2))
+ (suggestions (wcheck-get-suggestions wcheck-language text))
+ (choice (if (and (display-popup-menus-p) event)
+ (wcheck-choose-suggestion-popup
+ suggestions event)
+ (wcheck-choose-suggestion-minibuffer
+ suggestions))))
+ (when (and (stringp choice)
+ (markerp start)
+ (markerp end))
+ (with-current-buffer (marker-buffer start)
+ (if buffer-read-only
+ (message "Buffer is read-only")
+ (delete-region start end)
+ (goto-char start)
+ (insert choice)
+ (setq return-value choice))))
+ (if (markerp start) (set-marker start nil))
+ (if (markerp end) (set-marker end nil))))
+ return-value)
+ (wcheck-suggestion-error
+ (message "%s" (cdr error-data))
+ nil)))
(defun wcheck-get-suggestions (language text)
@@ -1292,16 +1306,17 @@ there aren't any)."
(parser suggestion-parser))
(cond ((not (wcheck-suggestion-program-configured-p language))
- (message
- "Language \"%s\": suggestion program or function is not configured"
- language)
- 'error)
+ (signal 'wcheck-suggestion-program-error
+ (format (concat "Language \"%s\": suggestion program or "
+ "function not configured")
+ language)))
((and (stringp program)
(not parser))
- (message "Language \"%s\": parser function is not configured"
- language)
- 'error)
+ (signal 'wcheck-suggestion-program-error
+ (format (concat "Language \"%s\": parser function is not "
+ "configured")
+ language)))
((stringp program)
(with-temp-buffer
- [elpa] 335/352: Fix typo in the doc string of wcheck-language-date, (continued)
- [elpa] 335/352: Fix typo in the doc string of wcheck-language-date, Stefan Monnier, 2014/07/07
- [elpa] 332/352: Add link to Marmalade package archive, Stefan Monnier, 2014/07/07
- [elpa] 352/352: * wcheck-mode: New package., Stefan Monnier, 2014/07/07
- [elpa] 299/352: Version 2011.07.27, Stefan Monnier, 2014/07/07
- [elpa] 290/352: Change README link to point to a newer commit, Stefan Monnier, 2014/07/07
- [elpa] 259/352: Rephrase documentation and comments, Stefan Monnier, 2014/07/07
- [elpa] 321/352: Make README.org more org-export-friendly, Stefan Monnier, 2014/07/07
- [elpa] 293/352: Remove duplicate word "function" from doc string, Stefan Monnier, 2014/07/07
- [elpa] 324/352: Leave author and timestamp out from exported README.org, Stefan Monnier, 2014/07/07
- [elpa] 294/352: Put case-fold in language options rather than email parser function, Stefan Monnier, 2014/07/07
- [elpa] 206/352: Käsitellään oikolukuehdotusten virheet toisella tavalla,
Stefan Monnier <=
- [elpa] 347/352: Add elpa pkg file to the repository (version 2014.5.17), Stefan Monnier, 2014/07/07
- [elpa] 178/352: Käytetään Emacs Lisp -tiedostojen vakiintuneita otsakkeita, Stefan Monnier, 2014/07/07
- [elpa] 315/352: Update copyright year to 2013, Stefan Monnier, 2014/07/07
- [elpa] 154/352: Optimoidaan hieman funktiota wcheck-collect-faces, Stefan Monnier, 2014/07/07
- [elpa] 165/352: Lisätään autoload-vihje funktiolle wcheck-spelling-suggestions, Stefan Monnier, 2014/07/07
- [elpa] 242/352: New feature: call custom functions from suggestion menu, Stefan Monnier, 2014/07/07
- [elpa] 153/352: Siirretään ajastimen käynnistys ja sammutus omiin funktioihinsa, Stefan Monnier, 2014/07/07
- [elpa] 295/352: Minor README formatting, Stefan Monnier, 2014/07/07
- [elpa] 343/352: Delete obsolete variable wcheck-read-or-skip-faces, Stefan Monnier, 2014/07/07
- [elpa] 204/352: Siirretään makrojen määritykset samaan paikkaan, Stefan Monnier, 2014/07/07