[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function to find outer parenthesis
From: |
Lou Vanek |
Subject: |
Re: Function to find outer parenthesis |
Date: |
Mon, 08 May 2006 18:24:47 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 |
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