This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
guile-c-edit-docstring
- To: guile at sourceware dot cygnus dot com
- Subject: guile-c-edit-docstring
- From: Keisuke Nishida <kxn30 at po dot cwru dot edu>
- Date: 07 May 2000 04:40:56 -0400
Hello,
I've written a little Emacs command guile-c-edit-docstring that can be
used to edit docstrings of Guile's C files.
If you type M-x guile-c-edit-docstring on a docstring, the docstring
is solely displayed in a separate buffer (by display-buffer) in texinfo
mode (and in font-lock-mode if you use it). Edit it as you like, and
type C-c C-c to finish editing and commit it.
Maybe I'll write guile-c-mode before long.
-- Kei
(defun guile-c-find-docstring ()
(save-excursion
(if (re-search-backward "^SCM_DEFINE" nil t)
(let ((start (progn (forward-line 2) (point))) doc)
(while (looking-at "[ \t]*\"")
(forward-line 1))
(cons start (- (point) 2))))))
(defun guile-c-edit-docstring ()
(interactive)
(let* ((region (guile-c-find-docstring))
(doc (if region (buffer-substring (car region) (cdr region)))))
(if (not doc)
(error "No docstring!")
(with-current-buffer (get-buffer-create "*Guile Docstring*")
(erase-buffer)
(insert doc)
(goto-char (point-min))
(while (not (eobp))
(if (looking-at "[ \t]*\"")
(delete-region (match-beginning 0) (match-end 0)))
(end-of-line)
(if (eq (char-before (point)) ?\")
(delete-backward-char 1))
(if (and (eq (char-before (point)) ?n)
(eq (char-before (1- (point))) ?\\))
(delete-backward-char 2))
(forward-line))
(goto-char (point-min))
(texinfo-mode)
(if global-font-lock-mode
(font-lock-fontify-buffer))
(local-set-key "\C-c\C-c" 'guile-c-edit-finish)
(switch-to-buffer-other-window (current-buffer))))))
(defun guile-c-edit-finish ()
(interactive)
(goto-char (point-min))
(while (not (eobp))
(insert "\"")
(end-of-line)
(insert (if (eobp) "\"" "\\n\""))
(forward-line 1))
(let ((doc (buffer-string)))
(kill-buffer (current-buffer))
(delete-window (selected-window))
(let ((region (guile-c-find-docstring)))
(goto-char (car region))
(delete-region (car region) (cdr region)))
(insert doc)))