From: Lou Vanek <vanek@acd.net>
Subject: Re: Function to find outer parenthesis
Date: Mon, 08 May 2006 18:24:47 +0000 [thread overview]
Message-ID: <e3o2d9$m4$1@sea.gmane.org> (raw)
In-Reply-To: <D6DE73398967E54096684518594D9931010534C2@exch-one.centrify.com>
This is what I use. It aint elegant, but it gets the job done.
Works in xemacs, but probably dies an agonizing death in gnu-emacs.
Argument 'tgtchar' can be specified to make it search for any character,
and the scan can go either forwards or backwards (see 'direc').
;;__________________________________________________________________________
;;;; Move point quickly past a certain character (and, if grouped together,
;;;; move point past entire group composed of this character.
;;;; Typically this function is used to scan for the next group of open
;;;; parentheses ( ?\( ) and move one character past them. This is a way of
;;;; quickly moving 'point' either 'up' or 'down' through s-expressions.
;;;; lv 5/5/2006
;;;;
;;;; ARGUMENTS
;;;; direc: 1, if move forward (default)
;;;; -1, if move backward
;;;;
;;;; tgtchar: character that is being scanned for.
;;;; Once this character is found, scanning continues until
;;;; all continuous occurrances of the character have been scanned by.
;;;; Default character: '(', which is represented in elisp as ?\(
;;;;
;;;; start: location in buffer where scan is to start.
;;;; Default: current point location.
(defun scan-and-move-past (&optional direc tgtchar start)
;(interactive
; (let ((s (read-string "Direction: " nil)))
; (list (string-to-number s))))
(if (null start)
(setf start (point)))
(if (null direc)
(setf direc 1))
(if (null tgtchar)
(setf tgtchar ?\( ))
(let (( p (+ start direc)))
(and
(do ((tgt (char-after p) (char-after (incf p direc))))
((or (null tgt) (char-equal tgtchar tgt )) (cond ((null tgt) nil)
((< p 1) nil)
(t p))))
(incf p direc)
(do ((tgt (char-after p) (char-after (incf p direc))))
((or (null tgt) (not (char-equal tgtchar tgt )))
(cond ((null tgt) nil)
((< p 1) nil)
(t p))
)
)
(goto-char p))))
(defun samp1 ()
(interactive)
(scan-and-move-past 1))
(defun samp-1 ()
(interactive)
(scan-and-move-past -1))
(define-key slime-mode-map (kbd "C-.") 'samp1)
(define-key slime-mode-map (kbd "C-,") 'samp-1)
Leo Liou wrote:
> In analyzing programs in the edit buffer, I sometimes wish I can do this
> - from where the cursor is, find the first outer "{" backward.
>
> I wonder if there is an existing function or way to do this.
> Thanks :-)
>
>
> Leo Liou
> Not a shred of evidence exists in favor of the notion that life is
> serious ...
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
next prev parent reply other threads:[~2006-05-08 18:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-08 15:23 Function to find outer parenthesis Leo Liou
2006-05-08 16:54 ` David Hansen
2006-05-08 18:24 ` Lou Vanek [this message]
[not found] ` <mailman.1588.1147113013.9609.help-gnu-emacs@gnu.org>
2006-05-09 14:25 ` Mathias Dahl
2006-05-09 21:21 ` Lou Vanek
[not found] <mailman.1576.1147101777.9609.help-gnu-emacs@gnu.org>
2006-05-08 15:38 ` David Kastrup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='e3o2d9$m4$1@sea.gmane.org' \
--to=vanek@acd.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).