[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Results of: [VOTE] New space-before-parens style

From: <kfogel_at_collab.net>
Date: 2006-02-15 01:00:16 CET

kfogel@collab.net writes:
> I think some modified version of Peter's elisp is probably going to be
> the way to go here. I'll take a look.

Okay, I think it's ready to run. Here's a diff first, so y'all can
check my work: http://www.red-bean.com/kfogel/reformat.diff.

Yes, Subversion still compiles afterwards. But I won't commit until I
hear that Julian Foad has looked at the diff :-). When I commit, I'll
update hacking.html too. Below is the code that did it:

--------------------8-<-------cut-here---------8-<-----------------------
;; To reformat the Subversion code:
;;
;; 1) Evaluate the elisp below.
;;
;; 2) Kill all your Subversion source file buffers, to avoid
;; unexpected "Reread from disk?" prompts during step (3).
;;
;; 3) Bring each .c or .h file into a buffer, run 'M-x kf-reformat',
;; save the buffer, kill the buffer. Lather, rinse, repeat,
;; presumably using a macro.
;;
;; 4) Search the diff for instances of "+#define". Some of those
;; (about thirty) will be macros whose formatting shouldn't have
;; been adjusted, and who are now incorrect because they look
;; parameterized when they should be non-parameterized. Go back
;; to their source files and fix them up.

(defun kf-after-sizeof ()
  "Return non-nil iff point is directly after the word 'sizeof'."
  ;; Don't bother with 'save-excursion', it's too heavyweight for this.
  (let ((opoint (point))
        ret)
    (forward-word -1)
    (if (looking-at "\\bsizeof\\b")
        (setq ret 't))
    (goto-char opoint)
    ret))

(defun kf-reformat ()
  "Reformat the current buffer to use no-space-after-function style.
Note that this function isn't smart enough to avoid reformatting
non-parameterized macros that happen to start with an open paren."
  (interactive)
  (buffer-disable-undo)
  (goto-char (point-min))
  (while (search-forward " (" (point-max) t)
    (unless (c-in-literal)
      (forward-char -2)
      (if (or (c-on-identifier) (kf-after-sizeof))
          (progn
            (delete-char 1)
            (let ((b (point))
                  (e (progn (forward-sexp) (point))))
              (goto-char b)
              (indent-region b e)
              ;; Backtrack a bit for nested function calls.
              (goto-char (+ b 1))))
        ;; Don't reformat for keywords like 'if', 'while', etc.
        (forward-char 2)))))

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Feb 15 02:42:14 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.