[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unairy delimited at point (snippet)

From: Andreas Röhler
Subject: unairy delimited at point (snippet)
Date: Tue, 10 Aug 2010 08:11:03 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv: Gecko/20100711 Thunderbird/3.0.6

just for fun...
comments welcome.




(defun unairy-delimited-atpt (char arg)
  "Takes any char inserted at prompt as delimiter.
Returns the string if any. With ARG 2 the bounds of this string are returned as a list, with ARG 3 it's lenght, a number.

If looking for parentized, braced at point etc., its delivered with thing-at-point-utils.el at  "
  (interactive "cinsert: \np")
      ((orig (point))
       (char (char-to-string char))
       (beg (search-backward char nil t 1))
       (end (progn
              (when (looking-at char)
                (goto-char (match-end 0)))
              (search-forward char nil t 1)))
        (when (ignore-errors (and (< beg end)(<= beg orig)(<= orig end)))
          (cond ((eq 1 arg)
                 (buffer-substring-no-properties beg end))
                ((eq 2 arg)
                 (list beg end))
                ((eq 3 arg)
                 (- end beg))))))
    (when (interactive-p) (message "%s" erg))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]