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

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

Re: lisp function to search-forward for lines with same indent


From: Kevin Rodgers
Subject: Re: lisp function to search-forward for lines with same indent
Date: Tue, 29 Aug 2006 13:42:31 -0600
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

Badari Kakumani wrote:
folks,

i have a large call-tree hierarchy represented as indented lines shown
below:

  File::Spec::Functions::__ANON__ x 1   0.00s = (0.00 + 0.00)s
    File::Spec::Unix::catfile x 1       0.00s = (0.00 + 0.00)s
      File::Spec::Unix::canonpath x 1   0.00s
      File::Spec::Unix::catdir x 1      0.00s = (0.00 + 0.00)s
        File::Spec::Unix::canonpath x 1         0.00s
  at::obj::BEGIN x 14   19.07s = (0.12 + 18.95)s

if my cursor is positioned at the first line shown in the above output,
i want to develop a function such that it finds the last-line
in the output shown -- a line with exactly two-spaces in the beginning
and then a non-space-charcter.

i want this to work for any other lines with a differing starting
indentation.

any clues on how to go about developing this lisp function or
any pointers to existing functions that do this will help.

to my surprise, in emacs, when i press:
   Esc Ctr-s ^ Space \sw
emacs is matching all lines that start with any number of spaces
(instead of matching lines with exactly one-space in the beginning
of line and a non-space character). not sure why it is behaving this
way.

Here's what I came up with:

(defun next-line-same-indentation ()
"Move point to the next line with the same indentation as the current line."
  (interactive)
  (let ((indentation (save-excursion
                       (buffer-substring (progn
                                           (beginning-of-line)
                                           (point))
                                         (1- (re-search-forward "\\S "))))))
    (re-search-forward (concat "^" (regexp-quote indentation) "\\S "))
    (backward-char)))

--
Kevin





reply via email to

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