unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Iterating/Finding all Comment- and String-Regions
@ 2009-12-17 12:51 Nordlöw
  2009-12-18 15:05 ` Andreas Röhler
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nordlöw @ 2009-12-17 12:51 UTC (permalink / raw)
  To: help-gnu-emacs

How can I find iterate over all the comment- and string-regions (BEG
END) in a buffer using the mode-specific syntax?

/Nordlöw


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

* Re: Iterating/Finding all Comment- and String-Regions
  2009-12-17 12:51 Iterating/Finding all Comment- and String-Regions Nordlöw
@ 2009-12-18 15:05 ` Andreas Röhler
  2009-12-18 16:00 ` Drew Adams
  2009-12-18 16:02 ` Drew Adams
  2 siblings, 0 replies; 4+ messages in thread
From: Andreas Röhler @ 2009-12-18 15:05 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw wrote:
> How can I find iterate over all the comment- and string-regions (BEG
> END) in a buffer using the mode-specific syntax?
> 
> /Nordlöw
> 


Hi,

function below works with python-mode and emacs-lisp.

However, you need some files from

https://code.launchpad.net/s-x-emacs-werkstatt/

Sorry for the inconvenience, but don't know a replacement for
`forward-string-atpt' `forward-comment-atpt'

You need
thing-at-point-utils.el
thingatpt-utils-base.el

which require from same location

beg-end.el
sh-beg-end.el
misc-utils.el

Probably these requirements are not crucial for your
function, don't know.

BTW once installed are related functions available, as
string-atpt, which returns string, comment-atpt etc.

HTH

Andreas

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

(defun next-comment-or-string ()
  "Jump forward to the end of next comment or string "
  (interactive)
  (lexical-let* ((pos (point))
                 (string-orig pos)
                 (comment-orig pos)
                 (comment-pos pos)
                 (string-pos pos))
    (save-excursion (when (forward-string-atpt) (setq string-pos (point))))
    (save-excursion (when (forward-comment-atpt) (setq comment-pos (point))))
    (cond ((and (< string-orig string-pos)(< comment-orig comment-pos))
           (if (< string-pos comment-pos)
               (goto-char string-pos)
             (goto-char comment-pos)))
          ((< comment-orig comment-pos)
           (goto-char comment-pos))
          ((< string-orig string-pos)
           (goto-char string-pos))
          (t (message "%s" "No further matching!")))))


;;;; Comments welcome... :)









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

* RE: Iterating/Finding all Comment- and String-Regions
  2009-12-17 12:51 Iterating/Finding all Comment- and String-Regions Nordlöw
  2009-12-18 15:05 ` Andreas Röhler
@ 2009-12-18 16:00 ` Drew Adams
  2009-12-18 16:02 ` Drew Adams
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2009-12-18 16:00 UTC (permalink / raw)
  To: 'Nordlöw', help-gnu-emacs

> How can I find iterate over all the comment- and string-regions (BEG
> END) in a buffer using the mode-specific syntax?

Consider taking advantage of font-locking. Look for text property `face' with
the particular face(s) you want - e.g. `font-lock-comment-face',
`font-lock-string-face', or `font-lock-doc-face'. This approach lets font-lock
do the work of parsing the mode-specific syntax. All you need to do is gather up
and treat the pieces of text that have the text property you want.

Since you use Icicles, take a look, Per, at function
`icicle-search-char-property-scan'. It does just that: iterates over the
occurrences of a given character property (i.e. a text or overlay property),
such as `face', that have a given value, such as `font-lock-comment-face'. Each
occurrence is a region such as you described.

It is used by the Icicles commands (`icicle-search-text-property',
`icicle-search-overlay-property', and `icicle-search-char-property') that let
you search for (regexp) matches among such occurrences only. It is the function
that builds the list of such occurrences as a set of completions, which are then
filtered interactively by your minibuffer input.
http://www.emacswiki.org/emacs/Icicles_-_Other_Search_Commands#toc2#SearchingTex
tProperties





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

* RE: Iterating/Finding all Comment- and String-Regions
  2009-12-17 12:51 Iterating/Finding all Comment- and String-Regions Nordlöw
  2009-12-18 15:05 ` Andreas Röhler
  2009-12-18 16:00 ` Drew Adams
@ 2009-12-18 16:02 ` Drew Adams
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2009-12-18 16:02 UTC (permalink / raw)
  To: 'Nordlöw', help-gnu-emacs

>
http://www.emacswiki.org/emacs/Icicles_-_Other_Search_Commands#toc2#SearchingTex
tProperties

Sorry, this is the correct URL:
http://www.emacswiki.org/emacs/Icicles_-_Other_Search_Commands#SearchingTextProp
erties





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

end of thread, other threads:[~2009-12-18 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-17 12:51 Iterating/Finding all Comment- and String-Regions Nordlöw
2009-12-18 15:05 ` Andreas Röhler
2009-12-18 16:00 ` Drew Adams
2009-12-18 16:02 ` Drew Adams

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