From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Piffer Newsgroups: gmane.emacs.help Subject: first steps in elisp Date: Thu, 24 Nov 2016 15:00:59 -0800 (PST) Message-ID: <271a22de-593b-479d-a3d7-4aecbce934fb@googlegroups.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1480028736 1198 195.159.176.226 (24 Nov 2016 23:05:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 24 Nov 2016 23:05:36 +0000 (UTC) Injection-Date: Thu, 24 Nov 2016 23:00:59 +0000 User-Agent: G2/1.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 25 00:05:31 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cA359-0007o5-2F for geh-help-gnu-emacs@m.gmane.org; Fri, 25 Nov 2016 00:05:31 +0100 Original-Received: from localhost ([::1]:42623 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cA35B-0002wW-26 for geh-help-gnu-emacs@m.gmane.org; Thu, 24 Nov 2016 18:05:33 -0500 X-Received: by 10.129.129.193 with SMTP id r184mr1053552ywf.114.1480028459450; Thu, 24 Nov 2016 15:00:59 -0800 (PST) X-Received: by 10.157.44.172 with SMTP id p41mr134892otb.6.1480028459398; Thu, 24 Nov 2016 15:00:59 -0800 (PST) Original-Path: usenet.stanford.edu!p16no818961qta.1!news-out.google.com!m27ni1388qtf.1!nntp.google.com!p16no818959qta.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Complaints-To: groups-abuse@google.com Original-Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a02:8388:e302:2880:5635:30ff:fe84:4739; posting-account=4QT6mgoAAAClKrMl9k-hLHvsKB5q9fw6 Original-NNTP-Posting-Host: 2a02:8388:e302:2880:5635:30ff:fe84:4739 Original-Xref: usenet.stanford.edu gnu.emacs.help:219012 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111792 Archived-At: I am trying to write some helper functions which should ease documentation = of C as per the method which my customers require (mostly repetition of par= ameters as Doxygen-enabled comments - I don't think that that's a good idea= , but the customer wants it). I coudn't find a package that was primitive e= nough to help me with the parsing - the code is embedded C and quite non-st= andard with respect to compiler extensions. So I tried to walk the extra mi= le and code a little elisp for fun. Which things are especially bad or unus= ual concerning both, Lisp and emacs? (defun ignore-multiline-comment (nlines) "assumes point is inside a C multiline comment /*. Advances until end of comment */ or nlines becomes 0" (if (zerop nlines) nil (if (looking-at ".*?\\*/") (progn (goto-char (match-end 0)) (ignore-line-comments nlines)) (beginning-of-line 2) (ignore-multiline-comment (1- nlines))))) =20 (defun ignore-line-comments (nlines) "return the text starting at point as a list, going nlines lines down, st= ripped of=20 all C comments (except pathological cases w/ string literals)" (if (zerop nlines) nil =20 (setq ml-e (if (looking-at "\\(.*?\\)/\\*") ;; test on /* comment (match-end 1) nil)) (setq sl-e (if (looking-at "\\(.*?\\)//") ;; test on // comment (match-end 1) nil)) (if (or sl-e ml-e) ;; any comment on line? (if (and ml-e (or (not sl-e) (< ml-e sl-e))) ;; is /* the = only or first comment? (progn (setq r (buffer-substring-no-properties (point) ml-e)= ) (goto-char ml-e) (cons r (ignore-multiline-comment nlines))) (setq r (buffer-substring-no-properties (point) sl-e)) (beginning-of-line 2) (cons r (ignore-line-comments (1- nlines)))) (looking-at ".*$") (setq r (buffer-substring-no-properties (car (match-data)) (cadr (mat= ch-data))) ) (beginning-of-line 2) (cons r (ignore-line-comments (1- nlines))))))