(defvar rebox-default-style 0 "*Preferred style for box comments.")
(defconst REBOX_HELP_FOR_LANGUAGE
"Box language is 100-none, 200-/*, 300-//, 400-#, 500-;, 600-%%")
(defconst REBOX_LANGUAGE_NONE 100)
(defconst REBOX_LANGUAGE_C 200)
(defconst REBOX_LANGUAGE_C++ 300)
(defconst REBOX_LANGUAGE_AWK 400)
(defconst REBOX_LANGUAGE_LISP 500)
(defconst REBOX_LANGUAGE_TEX 600)
(defun rebox-help-string-for-language (language)
(cond ((= language 0) "default language")
((= language REBOX_LANGUAGE_NONE) "no language")
((= language REBOX_LANGUAGE_C) "plain C")
((= language REBOX_LANGUAGE_C++) "C++")
((= language REBOX_LANGUAGE_AWK) "sh/Perl/make")
((= language REBOX_LANGUAGE_LISP) "LISP/assembler")
((= language REBOX_LANGUAGE_TEX) "TeX/PostScript")
(t "<Unknown Language>")))
(defconst REBOX_HELP_FOR_QUALITY
"Box quality/width is 10-simple, 20-rounded, 30-rounded or 40-starred")
(defconst REBOX_QUALITY_SIMPLE_ONE 10)
(defconst REBOX_QUALITY_ROUNDED_TWO 20)
(defconst REBOX_QUALITY_ROUNDED_THREE 30)
(defconst REBOX_QUALITY_STARRED_FOUR 40)
(defun rebox-help-string-for-quality (quality)
(cond ((= quality 0) "default quality")
((= quality REBOX_QUALITY_SIMPLE_ONE) "square or 1-wide")
((= quality REBOX_QUALITY_ROUNDED_TWO) "rounded or 2-wide")
((= quality REBOX_QUALITY_ROUNDED_THREE) "rounded or 3-wide")
((= quality REBOX_QUALITY_STARRED_FOUR) "starred or 4-wide")
(t "<Unknown Quality>")))
(defconst REBOX_HELP_FOR_TYPE
"Box type is 1-open, 2-half-single, 3-single, 4-half-double or 5-double")
(defconst REBOX_TYPE_OPEN 1)
(defconst REBOX_TYPE_HALF_SINGLE 2)
(defconst REBOX_TYPE_SINGLE 3)
(defconst REBOX_TYPE_HALF_DOUBLE 4)
(defconst REBOX_TYPE_DOUBLE 5)
(defun rebox-help-string-for-type (type)
(cond ((= type 0) "default type")
((= type REBOX_TYPE_OPEN) "opened box")
((= type REBOX_TYPE_HALF_SINGLE) "half normal")
((= type REBOX_TYPE_SINGLE) "full normal")
((= type REBOX_TYPE_HALF_DOUBLE) "half bold")
((= type REBOX_TYPE_DOUBLE) "full bold")
(t "<Unknown Type>")))
(defconst REBOX_MAX_LANGUAGE 6)
(defconst REBOX_MAX_QUALITY 4)
(defconst REBOX_MAX_TYPE 5)
(defun rebox-ask-for-style ()
(let (key language quality type)
(while (not language)
(message REBOX_HELP_FOR_LANGUAGE)
(setq key (read-char))
(if (and (>= key ?0) (<= key (+ ?0 REBOX_MAX_LANGUAGE)))
(setq language (- key ?0))))
(while (not quality)
(message REBOX_HELP_FOR_QUALITY)
(setq key (read-char))
(if (and (>= key ?0) (<= key (+ ?0 REBOX_MAX_QUALITY)))
(setq quality (- key ?0))))
(while (not type)
(message REBOX_HELP_FOR_TYPE)
(setq key (read-char))
(if (and (>= key ?0) (<= key (+ ?0 REBOX_MAX_TYPE)))
(setq type (- key ?0))))
(+ (* 100 language) (* 10 quality) type)))
(defun rebox-show-style (text style)
(message
(concat text (format " (%03d)" style)
": " (rebox-help-string-for-language (* (/ style 100) 100))
", " (rebox-help-string-for-quality (* (% (/ style 10) 10) 10))
", " (rebox-help-string-for-type (% style 10)))))
(defun rebox-validate-flag (flag)
(if (numberp flag)
(let ((value (if (< flag 0) (- flag) flag)))
(if (> (/ value 100) REBOX_MAX_LANGUAGE)
(error REBOX_HELP_FOR_LANGUAGE))
(if (> (% (/ value 10) 10) REBOX_MAX_QUALITY)
(error REBOX_HELP_FOR_QUALITY))
(if (> (% value 10) REBOX_MAX_TYPE)
(error REBOX_HELP_FOR_TYPE))))
(if (and (numberp flag) (<= flag 0))
(progn
(setq flag (- flag))
(if (not (zerop (/ flag 100)))
(setq rebox-default-style
(+ (* (/ flag 100) 100)
(% rebox-default-style 100))))
(if (not (zerop (% (/ flag 10) 10)))
(setq rebox-default-style
(+ (* (/ rebox-default-style 100) 100)
(* (% (/ flag 10) 10) 10)
(% rebox-default-style 10))))
(if (not (zerop (% flag 10)))
(setq rebox-default-style
(+ (* (/ rebox-default-style 10) 10)
(% flag 10))))
(rebox-show-style "Default style" rebox-default-style)
nil)
t))
(defun rebox-left-margin ()
(let ((margin -1))
(goto-char (point-min))
(while (not (eobp))
(skip-chars-forward " \t")
(if (not (looking-at "\n"))
(setq margin
(if (< margin 0)
(current-column)
(min margin (current-column)))))
(forward-line 1))
margin))
(defun rebox-right-margin ()
(let ((margin 0) period)
(goto-char (point-min))
(while (not (eobp))
(end-of-line)
(if (bobp)
(setq period 0)
(backward-char 1)
(setq period (if (looking-at "[.?!]") 1 0))
(forward-char 1))
(setq margin (max margin (+ (current-column) period)))
(forward-char 1))
margin))
(defun rebox-regexp-start (language)
(cond ((= language 0) "^[ \t]*\\(/\\*\\|//+\\|#+\\|;+\\|%+\\)")
((= language REBOX_LANGUAGE_NONE) "^\\(\\)")
((= language REBOX_LANGUAGE_C) "^[ \t]*\\(/\\*\\)")
((= language REBOX_LANGUAGE_C++) "^[ \t]*\\(//+\\)")
((= language REBOX_LANGUAGE_AWK) "^[ \t]*\\(#+\\)")
((= language REBOX_LANGUAGE_LISP) "^[ \t]*\\(;+\\)")
((= language REBOX_LANGUAGE_TEX) "^[ \t]*\\(%+\\)")))
(defun rebox-regexp-end (language)
(cond ((= language 0) "\\(\\*/\\|//+\\|#+\\|;+\\|%+\\)[ \t]*$")
((= language REBOX_LANGUAGE_NONE) "\\(\\)$")
((= language REBOX_LANGUAGE_C) "\\(\\*/\\)[ \t]*$")
((= language REBOX_LANGUAGE_C++) "\\(//+\\)[ \t]*$")
((= language REBOX_LANGUAGE_AWK) "\\(#+\\)[ \t]*$")
((= language REBOX_LANGUAGE_LISP) "\\(;+\\)[ \t]*$")
((= language REBOX_LANGUAGE_TEX) "\\(%+\\)[ \t]*$")))
(defun rebox-guess-language ()
(let ((language REBOX_LANGUAGE_NONE)
(value (* 100 REBOX_MAX_LANGUAGE)))
(while (not (zerop value))
(if (looking-at (rebox-regexp-start value))
(progn
(setq language value)
(setq value 0))
(setq value (- value 100))))
language))
(defun rebox-find-and-narrow ()
(save-excursion
(let (start end temp language)
(beginning-of-line)
(skip-chars-forward " \t\n")
(beginning-of-line)
(if (not (looking-at (rebox-regexp-start 0)))
(progn
(setq temp (point))
(if (re-search-forward "\\*/" nil t)
(progn
(re-search-backward "/\\*")
(if (> (point) temp)
(error "outside any comment block"))
(setq temp (point))
(beginning-of-line)
(skip-chars-forward " \t")
(if (not (= (point) temp))
(error "text before start of comment"))
(beginning-of-line))
(error "outside any comment block"))))
(setq start (point))
(setq language (rebox-guess-language))
(if (= language REBOX_LANGUAGE_C)
(progn
(search-forward "*/")
(if (not (looking-at "[ \t]*$"))
(error "text after end of comment"))))
(end-of-line)
(if (eobp)
(insert "\n")
(forward-char 1))
(setq end (point))
(goto-char start)
(while (and (not (bobp))
(if (= language REBOX_LANGUAGE_C)
(progn
(skip-chars-backward " \t\n")
(if (and (looking-at "[ \t]*\n[ \t]*/\\*")
(> (point) 2))
(progn
(backward-char 2)
(if (looking-at "\\*/")
(progn
(re-search-backward "/\\*")
(setq temp (point))
(beginning-of-line)
(skip-chars-forward " \t")
(if (= (point) temp)
(progn (beginning-of-line) t)))))))
(previous-line 1)
(looking-at (rebox-regexp-start language))))
(setq start (point)))
(goto-char end)
(while (looking-at (rebox-regexp-start language))
(if (= language REBOX_LANGUAGE_C)
(progn
(re-search-forward "[ \t]*/\\*")
(re-search-forward "\\*/")
(if (looking-at "[ \t]*$")
(progn
(beginning-of-line)
(forward-line 1)
(setq end (point)))))
(forward-line 1)
(setq end (point))))
(narrow-to-region start end))))
(defun rebox-reconstruct (refill margin language quality type)
(rebox-show-style "Style" (+ language quality type))
(let (right-margin nw nn ne ww ee sw ss se x xx)
(cond ((= language REBOX_LANGUAGE_NONE)
(cond ((= quality REBOX_QUALITY_SIMPLE_ONE)
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "") (setq sw "")
(setq ww "") (setq ee ""))
((= type REBOX_TYPE_HALF_SINGLE)
(setq nw "")
(setq ww "| ") (setq ee " |")
(setq sw "+-") (setq ss ?-) (setq se "-+"))
((= type REBOX_TYPE_SINGLE)
(setq nw "+-") (setq nn ?-) (setq ne "-+")
(setq ww "| ") (setq ee " |")
(setq sw "+-") (setq ss ?-) (setq se "-+"))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq nw "")
(setq ww "| ") (setq ee " |")
(setq sw "*=") (setq ss ?=) (setq se "=*"))
((= type REBOX_TYPE_DOUBLE)
(setq nw "*=") (setq nn ?=) (setq ne "=*")
(setq ww "| ") (setq ee " |")
(setq sw "*=") (setq ss ?=) (setq se "=*"))))
((or (= quality REBOX_QUALITY_ROUNDED_TWO)
(= quality REBOX_QUALITY_ROUNDED_THREE))
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "") (setq sw "")
(setq ww "| ") (setq ee " |"))
((= type REBOX_TYPE_HALF_SINGLE)
(setq nw "")
(setq ww "| ") (setq ee " |")
(setq sw "`-") (setq ss ?-) (setq se "-'"))
((= type REBOX_TYPE_SINGLE)
(setq nw ".-") (setq nn ?-) (setq ne "-.")
(setq ww "| ") (setq ee " |")
(setq sw "`-") (setq ss ?-) (setq se "-'"))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq nw "")
(setq ww "| " ) (setq ee " |" )
(setq sw "\\=") (setq ss ?=) (setq se "=/" ))
((= type REBOX_TYPE_DOUBLE)
(setq nw "/=" ) (setq nn ?=) (setq ne "=\\")
(setq ww "| " ) (setq ee " |" )
(setq sw "\\=") (setq ss ?=) (setq se "=/" ))))
((= quality REBOX_QUALITY_STARRED_FOUR)
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "") (setq sw "")
(setq ww "| ") (setq ee ""))
((= type REBOX_TYPE_HALF_SINGLE)
(setq nw "")
(setq ww "* ") (setq ee " *")
(setq sw "**") (setq ss ?*) (setq se "**"))
((= type REBOX_TYPE_SINGLE)
(setq nw "**") (setq nn ?*) (setq ne "**")
(setq ww "* ") (setq ee " *")
(setq sw "**") (setq ss ?*) (setq se "**"))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq nw "")
(setq ww "X ") (setq ee " X")
(setq sw "XX") (setq ss ?X) (setq se "XX"))
((= type REBOX_TYPE_DOUBLE)
(setq nw "XX") (setq nn ?X) (setq ne "XX")
(setq ww "X ") (setq ee " X")
(setq sw "XX") (setq ss ?X) (setq se "XX"))))))
((= language REBOX_LANGUAGE_C)
(cond ((= quality REBOX_QUALITY_SIMPLE_ONE)
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "") (setq sw "")
(setq ww "/* ") (setq ee " */"))
((= type REBOX_TYPE_HALF_SINGLE)
(setq nw "")
(setq ww "/* ") (setq ee " */")
(setq sw "/* ") (setq ss ?-) (setq se " */"))
((= type REBOX_TYPE_SINGLE)
(setq nw "/* ") (setq nn ?-) (setq ne " */")
(setq ww "/* ") (setq ee " */")
(setq sw "/* ") (setq ss ?-) (setq se " */"))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq nw "")
(setq ww "/* ") (setq ee " */")
(setq sw "/* ") (setq ss ?=) (setq se " */"))
((= type REBOX_TYPE_DOUBLE)
(setq nw "/* ") (setq nn ?=) (setq ne " */")
(setq ww "/* ") (setq ee " */")
(setq sw "/* ") (setq ss ?=) (setq se " */"))))
((or (= quality REBOX_QUALITY_ROUNDED_TWO)
(= quality REBOX_QUALITY_ROUNDED_THREE))
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "") (setq sw "")
(setq ww " ") (setq ee ""))
((= type REBOX_TYPE_HALF_SINGLE)
(setq nw "/*") (setq nn ? ) (setq ne " .")
(setq ww "| ") (setq ee " |")
(setq sw "`-") (setq ss ?-) (setq se "*/"))
((= type REBOX_TYPE_SINGLE)
(setq nw "/*") (setq nn ?-) (setq ne "-.")
(setq ww "| ") (setq ee " |")
(setq sw "`-") (setq ss ?-) (setq se "*/"))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq nw "/*" ) (setq nn ? ) (setq ne " \\")
(setq ww "| " ) (setq ee " |" )
(setq sw "\\=") (setq ss ?=) (setq se "*/" ))
((= type REBOX_TYPE_DOUBLE)
(setq nw "/*" ) (setq nn ?=) (setq ne "=\\")
(setq ww "| " ) (setq ee " |" )
(setq sw "\\=") (setq ss ?=) (setq se "*/" ))))
((= quality REBOX_QUALITY_STARRED_FOUR)
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "/* ") (setq nn ? ) (setq ne "")
(setq ww " * ") (setq ee "")
(setq sw " */") (setq ss ? ) (setq se ""))
((= type REBOX_TYPE_HALF_SINGLE)
(setq nw "/* ") (setq nn ? ) (setq ne " *")
(setq ww " * ") (setq ee " *")
(setq sw " **") (setq ss ?*) (setq se "**/"))
((= type REBOX_TYPE_SINGLE)
(setq nw "/**") (setq nn ?*) (setq ne "**")
(setq ww " * ") (setq ee " *")
(setq sw " **") (setq ss ?*) (setq se "**/"))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq nw "/* " ) (setq nn ? ) (setq ne " *\\")
(setq ww "|* " ) (setq ee " *|" )
(setq sw "\\**") (setq ss ?*) (setq se "**/" ))
((= type REBOX_TYPE_DOUBLE)
(setq nw "/**" ) (setq nn ?*) (setq ne "**\\")
(setq ww "|* " ) (setq ee " *|" )
(setq sw "\\**") (setq ss ?*) (setq se "**/" ))))))
(t
(if (and (= language REBOX_LANGUAGE_C++)
(= quality REBOX_QUALITY_SIMPLE_ONE))
(setq quality REBOX_QUALITY_ROUNDED_TWO))
(setq x (cond ((= language REBOX_LANGUAGE_C++) ?/)
((= language REBOX_LANGUAGE_AWK) ?#)
((= language REBOX_LANGUAGE_LISP) ?\ ((= language REBOX_LANGUAGE_TEX) ?%)))
(setq xx (make-string (/ quality 10) x))
(setq ww (concat xx " "))
(cond ((= type REBOX_TYPE_OPEN)
(setq nw "") (setq sw "") (setq ee ""))
((= type REBOX_TYPE_HALF_SINGLE)
(setq ee (concat " " xx))
(setq nw "")
(setq sw ww) (setq ss ?-) (setq se ee))
((= type REBOX_TYPE_SINGLE)
(setq ee (concat " " xx))
(setq nw ww) (setq nn ?-) (setq ne ee)
(setq sw ww) (setq ss ?-) (setq se ee))
((= type REBOX_TYPE_HALF_DOUBLE)
(setq ee (concat " " xx))
(setq xx (make-string (1+ (/ quality 10)) x))
(setq nw "")
(setq sw xx) (setq ss x) (setq se xx))
((= type REBOX_TYPE_DOUBLE)
(setq ee (concat " " xx))
(setq xx (make-string (1+ (/ quality 10)) x))
(setq nw xx) (setq nn x) (setq ne xx)
(setq sw xx) (setq ss x) (setq se xx)))))
(if (not (and flag (listp flag)))
(let ((fill-prefix (make-string margin ? ))
(fill-column (- fill-column (+ (length ww) (length ee)))))
(fill-region (point-min) (point-max))))
(setq right-margin (+ (rebox-right-margin) (length ww)))
(goto-char (point-min))
(if (and (= language REBOX_LANGUAGE_C)
(or (= quality REBOX_QUALITY_ROUNDED_TWO)
(= quality REBOX_QUALITY_ROUNDED_THREE))
(= type REBOX_TYPE_OPEN))
(progn
(skip-chars-forward " " (+ (point) margin))
(insert (make-string (- margin (current-column)) ? )
"/* ")
(end-of-line)
(forward-char 1)
(while (not (eobp))
(skip-chars-forward " " (+ (point) margin))
(insert (make-string (- margin (current-column)) ? )
ww)
(beginning-of-line)
(forward-line 1))
(backward-char 1)
(insert " */"))
(if (not (zerop (length nw)))
(progn
(indent-to margin)
(insert nw)
(if (or (not (eq nn ? )) (not (zerop (length ne))))
(insert (make-string (- right-margin (current-column)) nn)
ne))
(insert "\n")))
(while (not (eobp))
(skip-chars-forward " " (+ (point) margin))
(insert (make-string (- margin (current-column)) ? )
ww)
(end-of-line)
(if (not (zerop (length ee)))
(progn
(indent-to right-margin)
(insert ee)))
(beginning-of-line)
(forward-line 1))
(if (not (zerop (length sw)))
(progn
(indent-to margin)
(insert sw)
(if (or (not (eq ss ? )) (not (zerop (length se))))
(insert (make-string (- right-margin (current-column)) ss)
se "\n")))))))
(defun rebox-engine (flag)
(let ((undo-list buffer-undo-list)
(marked-point (point-marker))
(language (progn (goto-char (point-min)) (rebox-guess-language)))
(quality 0)
(type 0))
(untabify (point-min) (point-max))
(let ((indent-tabs-mode nil)
(previous-margin (rebox-left-margin))
actual-margin)
(if (= language REBOX_LANGUAGE_NONE)
nil
(goto-char (point-min))
(while (re-search-forward (rebox-regexp-start language) nil t)
(goto-char (match-beginning 1))
(delete-region (point) (match-end 1))
(insert (make-string (- (match-end 1) (point)) ? )))
(goto-char (point-min))
(while (re-search-forward (rebox-regexp-end language) nil t)
(replace-match "" t t)))
(if (= language REBOX_LANGUAGE_C)
(progn
(goto-char (point-min))
(while (re-search-forward "\\*/ */\\*" nil t)
(replace-match " " t t))
(goto-char (point-min))
(while (re-search-forward "^\\( *\\)|\\*\\(.*\\)\\*| *$" nil t)
(setq quality REBOX_QUALITY_STARRED_FOUR)
(setq type REBOX_TYPE_DOUBLE)
(replace-match "\\1 \\2" t))
(goto-char (point-min))
(while (re-search-forward "^\\( *\\)\\*\\(.*\\)\\* *$" nil t)
(setq quality REBOX_QUALITY_STARRED_FOUR)
(setq type REBOX_TYPE_SINGLE)
(replace-match "\\1 \\2" t))
(goto-char (point-min))
(while (re-search-forward "^\\( *\\)|\\(.*\\)| *$" nil t)
(setq quality REBOX_QUALITY_ROUNDED_TWO)
(replace-match "\\1 \\2" t))
(goto-char (point-min))
(if (zerop quality)
(while (re-search-forward "^\\( +\\)\\* " nil t)
(setq quality REBOX_QUALITY_STARRED_FOUR)
(setq type REBOX_TYPE_OPEN)
(replace-match "\\1 " t)))))
(goto-char (point-min))
(if (looking-at "^ *\\(--+\\|\\*\\*+\\)[.\+\\]? *\n")
(progn
(setq type REBOX_TYPE_SINGLE)
(replace-match "" t t))
(if (looking-at "^ *\\(==\\|XX+\\|##+\\|;;+\\)[.\+\\]? *\n")
(progn
(setq type REBOX_TYPE_DOUBLE)
(replace-match "" t t))))
(goto-char (point-max))
(previous-line 1)
(if (looking-at "^ *[`\+\\]?*--+ *\n")
(progn
(if (= type REBOX_TYPE_OPEN)
(setq type REBOX_TYPE_HALF_SINGLE))
(replace-match "" t t))
(if (looking-at "^ *[`\+\\]?*\\(==+\\|##+\\|;;+\\) *\n")
(progn
(if (= type REBOX_TYPE_OPEN)
(setq type REBOX_TYPE_HALF_DOUBLE))
(replace-match "" t t))
(if (looking-at "^ *\\*\\*+[.\+\\]? *\n")
(progn
(setq quality REBOX_QUALITY_STARRED_FOUR)
(setq type REBOX_TYPE_HALF_SINGLE)
(replace-match "" t t))
(if (looking-at "^ *XX+[.\+\\]? *\n")
(progn
(setq quality REBOX_QUALITY_STARRED_FOUR)
(setq type REBOX_TYPE_HALF_DOUBLE)
(replace-match "" t t))))))
(goto-char (point-min))
(while (re-search-forward " +$" nil t)
(replace-match "" t t))
(goto-char (point-min))
(if (looking-at "\n+")
(replace-match "" t t))
(goto-char (point-max))
(skip-chars-backward "\n")
(if (looking-at "\n\n+")
(replace-match "\n" t t))
(goto-char (point-min))
(while (re-search-forward "\n\n\n+" nil t)
(replace-match "\n\n" t t))
(setq actual-margin (rebox-left-margin))
(if (not (= previous-margin actual-margin))
(indent-rigidly (point-min) (point-max)
(- previous-margin actual-margin))))
(cond ((and (numberp flag) (not (zerop (/ flag 100))))
(setq language (* (/ flag 100) 100)))
((not (zerop (/ rebox-default-style 100)))
(setq language (* (/ rebox-default-style 100) 100))))
(cond ((and (numberp flag) (not (zerop (% (/ flag 10) 10))))
(setq quality (* (% (/ flag 10) 10) 10)))
((not (zerop (% (/ rebox-default-style 10) 10)))
(setq quality (* (% (/ rebox-default-style 10) 10) 10)))
((zerop quality)
(setq quality REBOX_QUALITY_ROUNDED_TWO)))
(cond ((and (numberp flag) (not (zerop (% flag 10))))
(setq type (% flag 10)))
((not (zerop (% rebox-default-style 10)))
(setq type (% rebox-default-style 10)))
((zerop type)
(setq type 1)))
(let ((indent-tabs-mode nil))
(rebox-reconstruct (not (and flag (listp flag)))
(rebox-left-margin)
language quality type))
(if indent-tabs-mode
(progn
(goto-char (point-min))
(while (re-search-forward "^[ \t][ \t]+" nil t)
(let ((column (current-column)))
(delete-region (match-beginning 0) (point))
(indent-to column)))))
(goto-char (marker-position marked-point))
(if (not (eq buffer-undo-list undo-list))
(let ((cursor buffer-undo-list))
(while (not (eq (cdr cursor) undo-list))
(if (car (cdr cursor))
(setq cursor (cdr cursor))
(rplacd cursor (cdr (cdr cursor)))))))))
(defvar c-mode-taarna-style nil "*Non-nil for Taarna team C-style.")
(defun taarna-mode ()
(interactive)
(if c-mode-taarna-style
(progn
(setq c-mode-taarna-style nil)
(setq c-indent-level 2)
(setq c-continued-statement-offset 2)
(setq c-brace-offset 0)
(setq c-argdecl-indent 5)
(setq c-label-offset -2)
(setq c-tab-always-indent t)
(setq rebox-default-style REBOX_QUALITY_ROUNDED_TWO)
(message "C mode: GNU style"))
(setq c-mode-taarna-style t)
(setq c-indent-level 4)
(setq c-continued-statement-offset 4)
(setq c-brace-offset -4)
(setq c-argdecl-indent 4)
(setq c-label-offset -4)
(setq c-tab-always-indent t)
(setq rebox-default-style
(+ REBOX_QUALITY_SIMPLE_ONE REBOX_TYPE_HALF_SINGLE))
(message "C mode: Taarna style")))
(defun rebox-region (flag)
(interactive "P")
(if (eq flag '-) (setq flag (rebox-ask-for-style)))
(if (rebox-validate-flag flag)
(save-restriction
(narrow-to-region (region-beginning) (region-end))
(rebox-engine flag))))
(defun rebox-comment (flag)
(interactive "P")
(if (eq flag '-) (setq flag (rebox-ask-for-style)))
(if (rebox-validate-flag flag)
(save-restriction
(rebox-find-and-narrow)
(rebox-engine flag))))