all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Function to find outer parenthesis
@ 2006-05-08 15:23 Leo Liou
  2006-05-08 16:54 ` David Hansen
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Leo Liou @ 2006-05-08 15:23 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 309 bytes --]

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 ...


[-- Attachment #1.2: Type: text/html, Size: 899 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Function to find outer parenthesis
       [not found] <mailman.1576.1147101777.9609.help-gnu-emacs@gnu.org>
@ 2006-05-08 15:38 ` David Kastrup
  0 siblings, 0 replies; 6+ messages in thread
From: David Kastrup @ 2006-05-08 15:38 UTC (permalink / raw)


"Leo Liou" <leo.liou@centrify.com> writes:

> 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 :-)

<C-M-up> runs the command backward-up-list
   which is an interactive compiled Lisp function in `lisp.el'.
It is bound to <C-M-up>, C-M-u, ESC <C-up>.
(backward-up-list &optional ARG)

Move backward out of one level of parentheses.
With ARG, do this that many times.
A negative argument means move forward but still to a less deep spot.

[back]


-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Function to find outer parenthesis
  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
       [not found] ` <mailman.1588.1147113013.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: David Hansen @ 2006-05-08 16:54 UTC (permalink / raw)


On Mon, 8 May 2006 08:23:14 -0700 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.
>

Not exactly what you want but close:

,----[ C-h f c-beginning-of-defun RET ]
| c-beginning-of-defun is an interactive compiled Lisp function in `cc-cmds.el'.
| (c-beginning-of-defun &optional ARG)
| 
| Move backward to the beginning of a defun.
| Every top level declaration that contains a brace paren block is
| considered to be a defun.
| 
| With a positive argument, move backward that many defuns.  A negative
| argument -N means move forward to the Nth following beginning.  Return
| t unless search stops due to beginning or end of buffer.
| 
| Unlike the built-in `beginning-of-defun' this tries to be smarter
| about finding the char with open-parenthesis syntax that starts the
| defun.
`----

,----[ C-h f backward-up-list RET ]
| backward-up-list is an interactive compiled Lisp function in `lisp.el'.
| It is bound to <C-M-up>, C-M-u, ESC <C-up>.
| (backward-up-list &optional ARG)
| 
| Move backward out of one level of parentheses.
| With ARG, do this that many times.
| A negative argument means move forward but still to a less deep spot.
`----

David

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Function to find outer parenthesis
  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
       [not found] ` <mailman.1588.1147113013.9609.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Lou Vanek @ 2006-05-08 18:24 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Function to find outer parenthesis
       [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
  0 siblings, 1 reply; 6+ messages in thread
From: Mathias Dahl @ 2006-05-09 14:25 UTC (permalink / raw)


Lou Vanek <vanek@acd.net> writes:

> 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.

How appropriate that you post in gnu.emacs.help then... ;)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Function to find outer parenthesis
  2006-05-09 14:25   ` Mathias Dahl
@ 2006-05-09 21:21     ` Lou Vanek
  0 siblings, 0 replies; 6+ messages in thread
From: Lou Vanek @ 2006-05-09 21:21 UTC (permalink / raw)


Mathias Dahl wrote:

> Lou Vanek <vanek@acd.net> writes:
> 
> 
>>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.
> 
> 
> How appropriate that you post in gnu.emacs.help then... ;)

my news reader doesn't say this is newsgroup 'gnu.emacs.help.'
i guess i picked the wrong week to quit smoking :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-09 21:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
     [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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.