Browse Source

Remember: Force selection of a valid template

Scot Beker writes:

>  I have org-remember working successfully (I can't believe that it took
>  me so long to experiment with it.  It has made a huge difference in my
>  work).
>
>  But if, after calling the extension with C-c r, I type a "wrong" tag
>  selector (e.g. I mistype a right one), I get
>  (1) the error message 'no template'  (good)
>  (2) a remember buffer without a bullet point, with the point at the
>  very top of the file (sure, what do I expect?)
>  (3) but, having realized my mistake, I can't get out of it gracefully.
>  I can't abort (C-c C-k), and can't (C-c C-c).
>  I get the error message    "Args out of range 0, 1"
>
>  Any idea whether I've set something up wrong or if org just has no
>  mercy on those who can't manage to type one of the selected values?
>  Otherwise, org-remember works well.

This situation is now avoided by forcing the selection of a valid
template.
Carsten Dominik 16 years ago
parent
commit
12ec4f4b67
2 changed files with 28 additions and 14 deletions
  1. 3 0
      lisp/ChangeLog
  2. 25 14
      lisp/org-remember.el

+ 3 - 0
lisp/ChangeLog

@@ -1,5 +1,8 @@
 2009-05-04  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-remember.el (org-select-remember-template): For the
+	selection of a valid template.
+
 	* org-latex.el (org-export-region-as-latex): Supply the
 	force-no-subtree argument.
 	(org-export-as-latex): Provide better limits when exporting the

+ 25 - 14
lisp/org-remember.el

@@ -318,6 +318,7 @@ RET at beg-of-buf -> Append to file as level 2 headline
 				    (append (list (nth 1 x) (car x)) (cddr x))
 				  (append (list (car x) "") (cdr x))))
 			      (delq nil pre-selected-templates2)))
+	   msg
 	   (char (or use-char
 		     (cond
 		      ((= (length templates) 1)
@@ -328,22 +329,32 @@ RET at beg-of-buf -> Append to file as level 2 headline
 			   (string-to-char org-force-remember-template-char)
 			 org-force-remember-template-char))
 		      (t
-		       (message "Select template: %s"
-				(mapconcat
-				 (lambda (x)
-				   (cond
-				    ((not (string-match "\\S-" (nth 1 x)))
-				     (format "[%c]" (car x)))
-				    ((equal (downcase (car x))
-					    (downcase (aref (nth 1 x) 0)))
-				     (format "[%c]%s" (car x)
-					     (substring (nth 1 x) 1)))
-				    (t (format "[%c]%s" (car x) (nth 1 x)))))
-				 templates " "))
-		       (let ((inhibit-quit t) (char0 (read-char-exclusive)))
+		       (setq msg (format
+				  "Select template: %s"
+				  (mapconcat
+				   (lambda (x)
+				     (cond
+				      ((not (string-match "\\S-" (nth 1 x)))
+				       (format "[%c]" (car x)))
+				      ((equal (downcase (car x))
+					      (downcase (aref (nth 1 x) 0)))
+				       (format "[%c]%s" (car x)
+					       (substring (nth 1 x) 1)))
+				      (t (format "[%c]%s" (car x) (nth 1 x)))))
+				   templates " ")))
+		       (let ((inhibit-quit t) char0)
+			 (while (not char0)
+			   (message msg)
+			   (setq char0 (read-char-exclusive))
+			   (when (and (not (assoc char0 templates))
+				      (not (equal char0 ?\C-g)))
+			     (message "No suche template \"%c\"" char0)
+			     (ding) (sit-for 1)
+			     (setq char0 nil)))
 			 (when (equal char0 ?\C-g)
 			   (jump-to-register remember-register)
-			   (kill-buffer remember-buffer))
+			   (kill-buffer remember-buffer)
+			   (error "Abort"))
 			 char0))))))
       (cddr (assoc char templates)))))