[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Iterating/Finding all Comment- and String-Regions
From: |
Andreas Röhler |
Subject: |
Re: Iterating/Finding all Comment- and String-Regions |
Date: |
Fri, 18 Dec 2009 16:05:13 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20081227) |
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... :)