help-gnu-emacs
[Top][All Lists]
Advanced

[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:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6

just for fun...
comments welcome.


Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/

;;;;;;;;;;;;;;;;;;;;;;;;

(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
https://code.launchpad.net/s-x-emacs-werkstatt  "
  (interactive "cinsert: \np")
  (let*
      ((orig (point))
       (char (char-to-string char))
       (beg (search-backward char nil t 1))
       (end (progn
              (when (looking-at char)
                (push-mark)
                (goto-char (match-end 0)))
              (search-forward char nil t 1)))
       (erg
        (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))))))
    (exchange-point-and-mark)
    (when (interactive-p) (message "%s" erg))
    erg))



reply via email to

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