Search This Blog

Saturday, April 11, 2009

comint-within-quotes in emacs

the function comint-within-quotes tells whether the cursor in quotes by counting the number of quotes from a start position to an end position.
but it can not handle an empty string like this: ""
it counts the first quote but ignores the second one.
and the single quote ' in common lisp has it's special using other than quoting something,oh,well,I mean it quotes something not with a pair but a single one.
so I hope I can have the function count only double quotes when editing common lisp and this is what I've defuned:

(defun comint-within-single-quotes (beg end)
  (let ((countsq (comint-how-many-region "\\(\\=\\|[^\\\\]\\)\'" beg end)))
    (= (mod countsq 2) 1)))
(defun comint-within-double-quotes (beg end)
  (let ((countdq (comint-how-many-region "\\(\\=\\|[^\\\\]\\)\"" beg end)))
    (= (mod countdq 2) 1)))
(defun* comint-within-quotes-2 (beg end &key (quotes :both))
  (case quotes
    (:both (comint-within-quotes beg end))
    (:single (comint-within-single-quotes beg end))
    (:double (comint-within-double-quotes beg end))))