Improve "indent foo.c" prep script
Change-Id: Ibb569b745954a11fb9c7751ad2d4140b922478fe Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:

committed by
Florin Coras

parent
08fc95568f
commit
987fdfa125
@ -1,34 +1,26 @@
|
|||||||
#!/usr/bin/emacs --script
|
#!/usr/bin/emacs --script
|
||||||
|
|
||||||
;; insert style boilerplate
|
;; Insert style boilerplate
|
||||||
|
;;
|
||||||
|
;; Breaking the string in half keeps emacs
|
||||||
|
;; from trying to interpret the local variable
|
||||||
|
;; settings e.g. when it reads the lisp source code
|
||||||
|
|
||||||
(defun insert-style-boilerplate () (interactive)
|
(defun insert-style-boilerplate () (interactive)
|
||||||
(save-excursion (goto-char (point-max))
|
(save-excursion (goto-char (point-max))
|
||||||
(insert "
|
(insert "
|
||||||
/*
|
/*
|
||||||
* fd.io coding-style-patch-verification: ON
|
* fd.io coding-style-patch-verification: ON
|
||||||
*
|
*
|
||||||
* Local Variables:
|
* Local Var" "iables:
|
||||||
* eval: (c-set-style \"gnu\")
|
* eval: (c-set-style \"gnu\")
|
||||||
* End:
|
* End:
|
||||||
*/")))
|
*/")))
|
||||||
|
|
||||||
;;
|
;; Insert indent-off ... indent-on brackets around
|
||||||
(defun fix-foreach () (interactive)
|
;; a certain xxx_foreach macro, etc. which "indent"
|
||||||
(save-excursion (goto-char (point-min))
|
;; completely screws up. Doesn't handle nesting, of which there
|
||||||
(while (search-forward-regexp
|
;; are few examples (fortunately).
|
||||||
"[pool|hash|clib_fifo|clib_bitmap]_foreach"
|
|
||||||
(point-max) t)
|
|
||||||
(move-beginning-of-line nil)
|
|
||||||
(open-line 1)
|
|
||||||
(c-indent-line-or-region)
|
|
||||||
(insert "/* *INDENT-OFF* */")
|
|
||||||
(search-forward "{")
|
|
||||||
(backward-char)
|
|
||||||
(forward-sexp)
|
|
||||||
(move-end-of-line nil)
|
|
||||||
(newline 1)
|
|
||||||
(c-indent-line-or-region)
|
|
||||||
(insert "/* *INDENT-ON* */"))))
|
|
||||||
|
|
||||||
(defun fix-initializer (what) (interactive)
|
(defun fix-initializer (what) (interactive)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
@ -46,6 +38,24 @@
|
|||||||
(c-indent-line-or-region)
|
(c-indent-line-or-region)
|
||||||
(insert "/* *INDENT-ON* */"))))
|
(insert "/* *INDENT-ON* */"))))
|
||||||
|
|
||||||
|
(defun fix-pool-foreach () (interactive)
|
||||||
|
(fix-initializer "pool_foreach *("))
|
||||||
|
|
||||||
|
(defun fix-hash-foreach () (interactive)
|
||||||
|
(fix-initializer "hash_foreach *("))
|
||||||
|
|
||||||
|
(defun fix-hash-foreach-pair () (interactive)
|
||||||
|
(fix-initializer "hash_foreach_pair *("))
|
||||||
|
|
||||||
|
(defun fix-clib-fifo-foreach () (interactive)
|
||||||
|
(fix-initializer "clib_fifo_foreach *("))
|
||||||
|
|
||||||
|
(defun fix-clib-bitmap-foreach () (interactive)
|
||||||
|
(fix-initializer "clib_bitmap_foreach *("))
|
||||||
|
|
||||||
|
(defun fix-foreach-ip-interface-address () (interactive)
|
||||||
|
(fix-initializer "foreach_ip_interface_address *("))
|
||||||
|
|
||||||
(defun fix-vlib-register-thread () (interactive)
|
(defun fix-vlib-register-thread () (interactive)
|
||||||
(fix-initializer "VLIB_REGISTER_THREAD *("))
|
(fix-initializer "VLIB_REGISTER_THREAD *("))
|
||||||
|
|
||||||
@ -56,20 +66,34 @@
|
|||||||
(fix-initializer "VLIB_REGISTER_NODE *("))
|
(fix-initializer "VLIB_REGISTER_NODE *("))
|
||||||
|
|
||||||
|
|
||||||
;; Driver routine which runs the set of keyboard macros
|
;; Driver routine which runs the set of functions
|
||||||
;; defined above, as well as the bottom boilerplate lisp fn.
|
;; defined above, as well as the bottom boilerplate function
|
||||||
|
|
||||||
(defun fd-io-styleify () (interactive)
|
(defun fd-io-styleify () (interactive)
|
||||||
(fix-foreach)
|
(fix-pool-foreach)
|
||||||
|
(fix-hash-foreach)
|
||||||
|
(fix-hash-foreach-pair)
|
||||||
|
(fix-foreach-ip-interface-address)
|
||||||
|
(fix-clib-fifo-foreach)
|
||||||
|
(fix-clib-bitmap-foreach)
|
||||||
(fix-vlib-register-thread)
|
(fix-vlib-register-thread)
|
||||||
(fix-vlib-cli-command)
|
(fix-vlib-cli-command)
|
||||||
(fix-vlib-register-node)
|
(fix-vlib-register-node)
|
||||||
(insert-style-boilerplate))
|
(insert-style-boilerplate))
|
||||||
|
|
||||||
(setq index 0)
|
|
||||||
(while (elt argv index)
|
;; When run as a script, this sexp
|
||||||
(message "Processing %s..." (elt argv index))
|
;; walks the list of files supplied on the command line.
|
||||||
(find-file (elt argv index))
|
;;
|
||||||
(fd-io-styleify)
|
;; (elt argv index) returns nil if you M-x eval-buffer
|
||||||
(setq index (1+ index)))
|
;; or M-x load-file the file, so we won't accidentally
|
||||||
(save-buffers-kill-emacs t)
|
;; evaluate (save-buffers-kill-emacs)...
|
||||||
|
|
||||||
|
(let ((index 0))
|
||||||
|
(if (elt argv index)
|
||||||
|
(while (elt argv index)
|
||||||
|
(message "Processing %s..." (elt argv index))
|
||||||
|
(find-file (elt argv index))
|
||||||
|
(fd-io-styleify)
|
||||||
|
(setq index (1+ index))
|
||||||
|
(save-buffers-kill-emacs t))))
|
||||||
|
Reference in New Issue
Block a user