unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* first steps in elisp
@ 2016-11-24 23:00 Mark Piffer
  2016-11-25  5:39 ` Marcin Borkowski
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mark Piffer @ 2016-11-24 23:00 UTC (permalink / raw)
  To: help-gnu-emacs

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 parameters 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 enough to help me with the parsing - the code is embedded C and quite non-standard with respect to compiler extensions. So I tried to walk the extra mile and code a little elisp for fun. Which things are especially bad or unusual 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)))))
 

(defun ignore-line-comments (nlines)
  "return the text starting at point as a list, going nlines lines down, stripped of 
all C comments (except pathological cases w/ string literals)"
  (if (zerop nlines)
      nil    
    (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 (match-data))) )
      (beginning-of-line 2)
      (cons r (ignore-line-comments (1- nlines))))))


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

end of thread, other threads:[~2017-04-12  6:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-24 23:00 first steps in elisp Mark Piffer
2016-11-25  5:39 ` Marcin Borkowski
2016-11-25  8:00 ` Joost Kremers
2016-12-21 17:57 ` Thien-Thi Nguyen
2017-04-12  6:26 ` Steve

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