[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: c-mode and c-indent-level



"TAKEMURA, Shin" <takemura@netbsd.org> writes:

> カンジです。c-argdecl-indent や knr-argdecl-offset は効果がないようです。

多分 knr-argdecl-intro じゃないかなあ.  参考までに僕が emacs-20.3 やら 
5 やらで使っている設定をつけておきます.

enami.
;;; $Id: netbsd.el,v 1.3 1997/09/19 23:13:48 enami Exp $

(require 'cc-mode)

;; NetBSD Kernel Normal Form style parameters for cc-mode.
(progn
  (let ((pair (assoc "NetBSD" c-style-alist)))
    (if pair
	(setq c-style-alist (delq pair c-style-alist))))
  (setq c-style-alist
	;; style parameter for NetBSD Kernel Normal Form.
	(cons '("NetBSD"
		(comment-column . 40)
		(c-basic-offset . 8)
		(c-comment-only-line-offset . 0)
		(c-hanging-comment-starter-p . nil)
		(c-hanging-comment-ender-p . nil)
		(c-offsets-alist . ((statement-block-intro . +)
				    (knr-argdecl-intro . +)
				    (substatement-open . 0)
				    (label . 0)
				    ;; ???
				    (topmost-intro-cont
				     . netbsd-nkf-topmost-intro-cont)
				    (statement . netbsd-knf-lineup-statement)
				    (statement-cont
				     . netbsd-knf-lineup-statement-cont)
				    (arglist-cont-nonempty
				     . netbsd-knf-arglist-cont-nonempty)
				    (arglist-close
				     . netbsd-knf-arglist-cont-nonempty))))
	      c-style-alist)))

(defun netbsd-knf-after-for-loop-p (pos)
  "True if POS is just after `for ('"
  (save-excursion
    (goto-char pos)
    (condition-case ()
	(progn (forward-char -5)	; (- (length "for ("))
	       (looking-at "\\bfor ("))
      (beginning-of-buffer nil))))

(defun netbsd-knf-lineup-statement (langelem)
  "Lineup statement with handling continuation line in for-loop condition."
  (cond ((netbsd-knf-after-for-loop-p (cdr langelem))
	 ;; -1 == 4 - 5 == `desired indent level' - `length of "for ("'
	 ;; and desired indent level == (/ c-basic-offset 2)
	 -1)
	(t 0)))

(defun netbsd-knf-lineup-statement-cont (langelem)
  "Lineup statement-cont with handling continuation line in for-loop\n\
condition."
  (cond ((netbsd-knf-after-for-loop-p (cdr langelem))
	 -1)
	;; 4 == (/ c-basic-offset 2)
	(t 4)))

(defun netbsd-knf-arglist-cont-nonempty (langelem)
  (cond ((save-excursion (goto-char (cdr langelem)) (bolp))
	 (save-excursion
	   (let ((eol (progn
			(goto-char (cdr langelem))
			(end-of-line)
			(point))))
	     (goto-char (cdr langelem))
	     (if (search-forward "\t" eol t)
		 (+ (current-column) (/ c-basic-offset 2))
	       (/ c-basic-offset 2)))))
	(t (/ c-basic-offset 2))))

(defun netbsd-nkf-topmost-intro-cont (langelem)
  (save-excursion
    (let ((base (save-excursion (goto-char (cdr langelem)) (current-column))))
      (back-to-indentation)
      (- (current-column) base))))