emacs-devel
[Top][All Lists]
Advanced

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

after-find-file-from-revert-buffer


From: Juanma Barranquero
Subject: after-find-file-from-revert-buffer
Date: Wed, 6 Apr 2011 02:28:12 +0200

I'm using lexical-binding = t to detect cases of unused arguments and
variables, unwanted shadowing of global variables, etc. (I'm not
planning to convert more packages to lexical-binding, just doing part
of the footwork in case someone wants to do it later.)

In function `after-find-file', one of the parameters is
AFTER-FIND-FILE-FROM-REVERT-BUFFER, whose purpose is to bind that
(undocumented) variable so code run from inside `after-find-file' can
detect whether the function was called from revert-buffer or not.

Its only use, now and since the parameter's and variable's
introduction sixteen years ago, is in the `saveplace-find-file-hook'
function, run from `find-file-hook', to decide whether to move the
cursor or not.

So I want to rename the argument to CALLED-FROM-REVERT-BUFFER-P, and
use a let inside `after-find-file'

  (let ((after-find-file-from-revert-buffer called-from-revert-buffer-p))
  ;; whatever
  ...)

To strictly keep the current semantics, the "whatever" inside that
`let' should be all the current code of `after-find-file'. But that
seems ugly and wasteful, and I think we can go forth with just
let-binding the inside of the final (unless nomodes ...) form:

  (unless nomodes
    (let ((after-find-file-from-revert-buffer called-from-revert-buffer-p))
      (when (and view-read-only view-mode)
        (view-mode-disable))
      (normal-mode t)
      ;; If requested, add a newline at the end of the file.
      (and (memq require-final-newline '(visit visit-save))
           (> (point-max) (point-min))
           (/= (char-after (1- (point-max))) ?\n)
           (not (and (eq selective-display t)
                     (= (char-after (1- (point-max))) ?\r)))
           (save-excursion
             (goto-char (point-max))
             (insert "\n")))
      (when (and buffer-read-only
                 view-read-only
                 (not (eq (get major-mode 'mode-class) 'special)))
        (view-mode-enter))
      (run-hooks 'find-file-hook))))

Additionally, we could document the variable, or find another, less
ugly way to pass that information back to saveplace.el and remove the
variable altogether.

Comments?

TIA,

    Juanma



reply via email to

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