From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matthew Swift Newsgroups: gmane.emacs.bugs Subject: fixup of some indent.el confusion Date: Sun, 17 Nov 2002 13:08:21 -0500 Sender: bug-gnu-emacs-admin@gnu.org Message-ID: <200211171808.gAHI8L2U029232@beth.swift.xxx> NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1037557684 19134 80.91.224.249 (17 Nov 2002 18:28:04 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 17 Nov 2002 18:28:04 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18DU9J-0004yE-00 for ; Sun, 17 Nov 2002 19:28:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18DUA2-0001Mr-00; Sun, 17 Nov 2002 13:28:46 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18DTqU-0006i9-00 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2002 13:08:34 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18DTqQ-0006fZ-00 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2002 13:08:32 -0500 Original-Received: from pool-68-160-52-23.bos.east.verizon.net ([68.160.52.23] helo=beth.swift.xxx) by monty-python.gnu.org with esmtp (Exim 4.10) id 18DTqP-0006fF-00 for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2002 13:08:29 -0500 Original-Received: from alum.mit.edu (swift@localhost [127.0.0.1]) by beth.swift.xxx (8.12.6/8.12.6/Debian-6) with ESMTP id gAHI8L2U029232 for ; Sun, 17 Nov 2002 13:08:21 -0500 Original-To: bug-gnu-emacs@gnu.org Gcc: nnfolder+archive:sent.messages X-Mailscanner: clean (beth.swift.xxx) Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:3892 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:3892 This bug report will be sent to the Free Software Foundation, not to your local site managers! Please write in English, because the Emacs maintainers do not have translators to read other languages for them. Your bug report will be posted to the bug-gnu-emacs@gnu.org mailing list, and to the gnu.emacs.bug news group. In GNU Emacs 21.2.1 (i386-debian-linux-gnu, X toolkit, Xaw3d scroll bars) of 2002-11-06 on beth, modified by Debian configured using `configure i386-debian-linux-gnu --prefix=/usr/local --sharedstatedir=/var/lib --libexecdir=/usr/local/lib --localstatedir=/var/lib --infodir=/usr/local/share/info --mandir=/usr/local/share/man --with-pop=yes --with-x=yes --with-x-toolkit=athena --without-gif' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: en_US locale-coding-system: iso-latin-1 default-enable-multibyte-characters: t Please describe exactly what actions triggered the bug and the precise symptoms of the bug: I have been using the following fixup code for 10 or more hours of general Emacs use, so they probably work as intended. I noticed that sometimes `indent-region' in shell-script-mode would not work, though tabbing on individual lines did work. When I investigated, I found that `indent-region-function' was set to some inappropriate thing from xrdb-mode. I concluded that the basic cause was that `indent-function-region' ought to be buffer-local. While making that change, I took the opportunity to correct mistakes in a few documentation strings and to clarify their wording. I think these revised functions suitable to drop into indent.el as replacements -- that's how I've been using them. If a patch is more helpful, ask and I will create one -- I develop and keep this kind of fix in version-keyed runtime patch files like below rather than revising entire libraries, or else it would be too complicated to distinguish my own code from standard. (eval-after-load "indent" '(progn ;; Matthew Swift 16 Nov 2002 ;; I contribute these changes to the FSF. ;; redefine these functions and variables from Emacs 21.2 ;; originals ;; Motivation: ;; Some modes say: ;; ;; (make-local-variable 'indent-region-function) ;; ;; but others just `setq' `indent-region-function'. The most ;; recent mode to do so sets the global value that is then used ;; inappropriately by modes that do not set their own value, e.g., ;; sh-mode. ;; Therefore I make `indent-region-function' and ;; `indent-line-function' buffer local. The global value of ;; `indent-region-function' in buffers whose mode has not set its ;; own value will then be nil, causing `indent-region' to use ;; `indent-line-function', which may have been set by the mode, ;; and if not will default to `indent-to-left-margin', giving ;; default behavior likely to be more stable, not to mention more ;; appropriate, than to indent by the means appropriate to ;; whatever Emacs buffer last set the mode itself. ;; The docstrings of these funcs and vars were incorrect and ;; somewhat confusing anyway. (defvar indent-line-function 'indent-to-left-margin "Buffer-local variable naming function to use to indent the current line.") (make-variable-buffer-local 'indent-line-function) (defun indent-according-to-mode () "Indent line in proper way for current major mode. The buffer-local variable `indent-line-function' determines how to indent the line. Change that variable rather than redefining this function." ;; See comments in the function `indent-region' for the reason ;; this function should not be changed. (interactive) (funcall indent-line-function)) (defvar indent-region-function nil "Buffer-local variable naming function to use to indent a region. The function will be passed two arguments delimiting the region. A value of nil means use the function `indent-according-to-mode'.") (make-variable-buffer-local 'indent-region-function) (defun indent-region (start end column) "Indent each nonblank line in the region. With a numeric prefix argument, indent each line to that column. With no prefix argument, indent with the first of the following three methods that applies: 1) If `fill-prefix' is non-nil, insert `fill-prefix' at the beginning of each line in the region that does not already begin with it. 2) If `indent-region-function' is non-nil, indent the region with the function it names. 3) Indent the region with the function `indent-according-to-mode'. Called from a program, START and END specify the region to indent. Third argument COLUMN, a raw prefix argument \(plain integers are allowed\), determines indentation as described above." (interactive "r\nP") (if (null column) (if fill-prefix (save-excursion (goto-char end) (setq end (point-marker)) (goto-char start) (let ((regexp (regexp-quote fill-prefix))) (while (< (point) end) (or (looking-at regexp) (and (bolp) (eolp)) (insert fill-prefix)) (forward-line 1)))) (if indent-region-function (funcall indent-region-function start end) (save-excursion (goto-char end) (setq end (point-marker)) (goto-char start) (or (bolp) (forward-line 1)) (while (< (point) end) (or (and (bolp) (eolp)) ;; We could simply `(indent-according-to-mode)' ;; here, but we call `indent-line-function' ;; directly instead, because it saves the ;; overhead of an extra function call. The ;; price is that one can't redefine ;; `indent-according-to-mode' without ;; invalidating the claim in the docstring above ;; that this function uses ;; `indent-according-to-mode'. (funcall indent-line-function)) (forward-line 1)) (move-marker end nil)))) (setq column (prefix-numeric-value column)) (save-excursion (goto-char end) (setq end (point-marker)) (goto-char start) (or (bolp) (forward-line 1)) (while (< (point) end) (delete-region (point) (progn (skip-chars-forward " \t") (point))) (or (eolp) (indent-to column 0)) (forward-line 1)) (move-marker end nil)))) ))