Subject: Ispell string or comment

From: Lennart Borgman <[email-masked]>
Date: Sat, 12 Jun 2010 19:57:43 +0200

Here is a suggestion for a function ispell-comment-or-string for spell
checking of current comment or string, see attachement.
=== modified file 'lisp/textmodes/ispell.el'
--- trunk/lisp/textmodes/ispell.el	2010-05-13 10:36:03 +0000
+++ patched/lisp/textmodes/ispell.el	2010-06-12 17:53:38 +0000
@@ -3266,11 +3266,21 @@

 ;;;###autoload
-(defun ispell-comments-and-strings ()
+(defun ispell-comments-and-strings (only-current)
   "Check comments and strings in the current buffer for spelling errors."
-  (interactive)
+  (interactive (list nil))
+  (let (state done)
+    (if (not only-current)
   (goto-char (point-min))
-  (let (state done)
+      (let* ((here (point))
+             (state (parse-partial-sexp (point-min) (point)))
+             (inside (or (nth 3 state) (nth 4 state)))
+             (start (when inside (nth 8 state))))
+        (if start
+            (goto-char start)
+          (setq done t)
+          (goto-char here)
+          (message "Not inside a string or comment"))))
     (while (not done)
       (setq done t)
       (setq state (parse-partial-sexp (point) (point-max)
@@ -3282,8 +3292,14 @@
 	    (if (or (nth 3 state) (nth 4 state))
 		(error "Unterminated string or comment"))
 	    (save-excursion
-	      (setq done (not (ispell-region start (point))))))))))
+	      (setq done (not (ispell-region start (point)))))))
+      (when only-current (setq done t)))))
 
+;;;###autoload
+(defun ispell-comment-or-string ()
+  "Check comments or strings at point for spelling errors."
+  (interactive)
+  (ispell-comments-and-strings t))
 
 ;;;###autoload
 (defun ispell-buffer ()