bug-gnu-emacs
[Top][All Lists]
Advanced

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

fixup of some indent.el confusion


From: Matthew Swift
Subject: fixup of some indent.el confusion
Date: Sun, 17 Nov 2002 13:08:21 -0500

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 address@hidden 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 <address@hidden> 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))))
    ))








reply via email to

[Prev in Thread] Current Thread [Next in Thread]