From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: Iterating/Finding all Comment- and String-Regions Date: Fri, 18 Dec 2009 16:05:13 +0100 Message-ID: <4B2B9A29.5090403@easy-emacs.de> References: <2d31ae05-8ff5-4225-8cc2-57e95e1ebea0@d21g2000yqn.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1261148760 28016 80.91.229.12 (18 Dec 2009 15:06:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 18 Dec 2009 15:06:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 18 16:05:53 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NLeOd-0004sb-TQ for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Dec 2009 16:05:36 +0100 Original-Received: from localhost ([127.0.0.1]:36648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLeOe-0000Kp-0y for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Dec 2009 10:05:36 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLeOI-0000HO-85 for help-gnu-emacs@gnu.org; Fri, 18 Dec 2009 10:05:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLeOD-0000F9-LZ for help-gnu-emacs@gnu.org; Fri, 18 Dec 2009 10:05:13 -0500 Original-Received: from [199.232.76.173] (port=52237 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLeOD-0000Ez-D0 for help-gnu-emacs@gnu.org; Fri, 18 Dec 2009 10:05:09 -0500 Original-Received: from moutng.kundenserver.de ([212.227.17.10]:57192) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLeOC-0004An-PW for help-gnu-emacs@gnu.org; Fri, 18 Dec 2009 10:05:09 -0500 Original-Received: from [192.168.178.27] (p54BEB750.dip0.t-ipconnect.de [84.190.183.80]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0MTvSD-1NUHNA1K8f-00RH9B; Fri, 18 Dec 2009 16:05:06 +0100 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: <2d31ae05-8ff5-4225-8cc2-57e95e1ebea0@d21g2000yqn.googlegroups.com> X-Provags-ID: V01U2FsdGVkX19R6RmYSMOU1RV1sVH/Xlieiw26xiYi4/+zbJh AssBikZTMgaXEJcYlWMXruCC60v/FpeavcyjbCUlKqdUHR9r18 dyfKFjgqXh6w6uC7omWNC1N896ZpZSPDz7YClxovxo= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70730 Archived-At: 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... :)