From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: cc-mode adds newlines Date: Mon, 22 Nov 2004 10:52:17 -0500 Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1101138833 7497 80.91.229.6 (22 Nov 2004 15:53:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 22 Nov 2004 15:53:53 +0000 (UTC) Cc: bug-cc-mode@gnu.org, Alan Mackenzie , Andries.Brouwer@cwi.nl, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 22 16:53:39 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CWGVW-0000Bq-00 for ; Mon, 22 Nov 2004 16:53:39 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CWGeY-0005pi-VN for ged-emacs-devel@m.gmane.org; Mon, 22 Nov 2004 11:02:59 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CWGeM-0005oU-P1 for emacs-devel@gnu.org; Mon, 22 Nov 2004 11:02:46 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CWGeL-0005o2-Ry for emacs-devel@gnu.org; Mon, 22 Nov 2004 11:02:46 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CWGeL-0005nz-OE for emacs-devel@gnu.org; Mon, 22 Nov 2004 11:02:45 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CWGUj-00008j-5o; Mon, 22 Nov 2004 10:52:49 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id D06958282A8; Mon, 22 Nov 2004 10:52:48 -0500 (EST) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 426164AC4E0; Mon, 22 Nov 2004 10:52:18 -0500 (EST) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id 94A028CA69; Mon, 22 Nov 2004 10:52:17 -0500 (EST) Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Mon, 22 Nov 2004 09:07:20 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=0, requis 5) X-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:30250 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:30250 > I think we should add a variable require-final-newline-modes which > would be a list of mode names. run-mode-hook could see if the current > mode is in require-final-newline-modes, and if so, set > require-final-newline to require-final-newline-mode-value. The > default for require-final-newline-mode-value would be :ask, but if a > user sets it to t, then all the appriate modes would set > require-final-newline to t. I think that would be silly. Tons of variable might want to be set differently in different modes. Do we really want to add all the corresponding foo-modes side-variables? I think we'd be better off with a more generic solution. I.e. we should aim for a way to specify per-mode settings in custom. That would be a lot more useful and wouldn't require adding any new variable. Here is one way it could work: - instead of `:type foo' use `:type (per-mode foo)' where (per-mode foo) stands for something like (repeat (cons mode foo)) where the list of modes can be obtained doing (let ((modes nil) mode) (mapatoms (lambda (s) (if (and (string-match "-mode-hook\\'" (symbol-name s)) (fboundp (intern (concat (setq mode (substring (symbol-name s) 0 (match-beginning 0))) "-mode")))) (push mode modes)))) modes) - set custom-get and custom-set functions could look like: (defun custom-set-per-mode (var vals) (put var 'custom-per-mode vals) (dolist (setting vals) (let ((mode (car setting)) (value (cdr setting))) (if (eq t mode) (set-default var value) (let ((fun (intern (concat "custom-set-" mode "-" (symbol-name var))))) (unless (fboundp fun) (fset fun `(lambda () (let ((val (assoc ',mode (get ',var 'custom-per-mode)))) (if val (set (make-local-variable ',var) (cdr val))))))) (add-hook (intern (concat mode "-mode-hook")) fun)))))) (defun custom-get-per-mode (var) (let* ((val (get var 'custom-per-mode)) (defval (assq t val))) (unless (eq (cdr defval) (default-value var)) ;; It was changed somehow... (setcdr defval (default-value var))) val)) Ideally we should even provide such per-mode settings for *all* custom variables, without having to change the `defcustom'. Stefan