Commit 4d235ac7 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

Unconditionally add to comint-output-filter-functions.

(auto-show-mode): Command renamed from auto-show-toggle.
Handle an arg in the standard way.
(auto-show-mode): Variable renamed from auto-show-enable.
parent 495a2b0a
;; LCD Archive Entry: ;;; This file is in the public domain.
;; auto-show|Pete Ware|ware@cis.ohio-state.edu|
;; Automatically scroll horizontally|
;; 95-02-24|1.9|~/misc/auto-show.el|
;;
;;;
;;; Author:
;;;
;;; Pete Ware ware@cis.ohio-state.edu
;;; CIS Dept, Ohio State University w/ (614) 292-8501
;;; 774 Dreese, 2015 Neil Ave. h/ (614) 791-1347
;;; Columbus, OH 43210 http://www.cis.ohio-state.edu/~ware
;;;
;;;
;;; Modification history:
;;; 02/24/95 Added auto-show-show-left-margin-threshold so that if
;;; there is anyway for the left margin to be displayed it is.
;;; 02/24/95 Only scroll window if it matches current buffer. Added
;;; function for enabeling scrolling in comint buffers on output.
;;; 02/13/95 Aded Kevin Broadey <KevinB@bartley.demon.co.uk> fix so that
;;; it doesn't scroll if we are at window border and at the
;;; end of the line (i.e. newline character)
;;; 02/10/95 jeff.dwork@amd.com added auto-show-toggle function.
;;; 02/08/95 Added auto-show-enable as per
;;; jeff.dwork@amd.com (Jeff Dwork)'s suggestion. Cleaned up
;;; documentation.
;;; 02/07/95 Rewrote for emacs 19: much, much cleaner. Renamed auto-show
;;; 8/6/90 Make next-line/previous-line do better job following movement.
;;; 3/21/90 better calculation of w-width in e-make-point-visible
;;; test for truncated windows
;;; added substitute-in-keymap
;;; renamed to auto-horizontal
;;; added backward-delete-char
;;; 8/13/88 Created
;;; ;;; Keywords: scroll display minor-mode
;;; This is a rewrite of auto-horizontal. It is comparable in ;;; Author: Pete Ware <ware@cis.ohio-state.edu>
;;; functionality to hscroll.el except it is not a minor mode and does ;;; Maintainer: FSF
;;; not use any timers. This file provides functions that
;;; Commentary:
;;; This file provides functions that
;;; automatically scroll the window horizontally when the point moves ;;; automatically scroll the window horizontally when the point moves
;;; off the left or right side of the window. To load it just add: ;;; off the left or right side of the window.
;;; (require 'auto-show)
;;; to your .emacs. ;;; Once this library is loaded, automatic horizontal scrolling
;;; ;;; occurs whenever long lines are being truncated.
;;; Setting the variable ``truncate-lines'' to non-nil causes long ;;; To request truncation of long lines, set the variable
;;; lines to disappear off the end of the screen instead of wrapping ;;; Setting the variable `truncate-lines' to non-nil.
;;; to the beginning of the next line. To make this the default for ;;; You can do this for all buffers as follows:
;;; all buffers add the following line to your .emacs (sans ;;;):
;;; ;;;
;;; (set-default 'truncate-lines t) ;;; (set-default 'truncate-lines t)
;;;
;;; However, I've found that I only want this when I'm editing C code. ;;; Here is how to do it for C mode only:
;;; Accordingly I have something like the following in my .emacs:
;;; ;;;
;;; (set-default 'truncate-lines nil) ; this is the original value ;;; (set-default 'truncate-lines nil) ; this is the original value
;;; (defun my-c-mode-hook () ;;; (defun my-c-mode-hook ()
...@@ -61,66 +28,54 @@ ...@@ -61,66 +28,54 @@
;;; (add-hook 'c-mode-hook 'my-c-mode-hook) ;;; (add-hook 'c-mode-hook 'my-c-mode-hook)
;;; ;;;
;;; ;;;
;;; As a finer level of control, one can still have truncated lines but ;;; As a finer level of control, you can still have truncated lines but
;;; without the automatic left and right scrolling by setting the buffer ;;; without the automatic horizontal scrolling by setting the buffer
;;; local variable ``auto-show-enable'' to nil. The default value is t. ;;; local variable `auto-show-mode' to nil. The default value is t.
;;; The command ``auto-show-toggle'' will toggle the value of ;;; The command `auto-show-mode' toggles the value of the variable
;;; ``auto-show-enable''. ;;; `auto-show-mode'.
;;;
;;;
;;; I also like the output from my shell's (and other comint.el based commands)
;;; to scroll on output. One can call:
;;;
;;; (auto-show-comint-make-point-visible)
;;;
;;; which adds auto-show-make-point-visible to comint-output-filter-functions.
(provide 'auto-show)
;;;************************************************************
;;;*
;;;* Define Automatic Horizontal Scrolling Functions
;;;*
;;;************************************************************
(add-hook 'post-command-hook 'auto-show-make-point-visible) ;;; Code:
(defvar auto-show-enable t (defvar auto-show-mode t
"*Allows one to turn off automatic horizontal scrolling on a per buffer "*Non-nil enables automatic horizontal scrolling, when lines are truncated.
basis independent of whether truncate-lines is t. The default value is t. The default value is t. To change the default, do this:
To change the default: (set-default 'auto-show-mode nil)
(set-default 'auto-show-enable nil) See also command `auto-show-mode'.
Any time auto-show-enable is changed it is only in the current buffer: This variable has no effect when lines are not being truncated.")
(setq auto-show-enable nil)
turns it on for this buffer.
See also command `auto-show-toggle'.")
(make-variable-buffer-local 'auto-show-enable) (make-variable-buffer-local 'auto-show-mode)
(defvar auto-show-shift-amount 8 (defvar auto-show-shift-amount 8
"*Extra amount to shift a line when point is not visible.") "*Extra columns to scroll. for automatic horizontal scrolling.")
(defvar auto-show-show-left-margin-threshold 50 (defvar auto-show-show-left-margin-threshold 50
"*Point must be before this column for us to try and make the left margin "*Threshold column for automatic horizontal scrolling to the right.
If point is before this column, we try to scroll to make the left margin
visible. Setting this to 0 disables this feature.") visible. Setting this to 0 disables this feature.")
(defun auto-show-truncationp () (defun auto-show-truncationp ()
"True if truncation is on for current window." "True if line truncation is enabled for the selected window."
(or truncate-lines (or truncate-lines
(and truncate-partial-width-windows (and truncate-partial-width-windows
(< (window-width) (frame-width))))) (< (window-width) (frame-width)))))
(defun auto-show-toggle () ;;;###autoload
"Toggle value of auto-show-enable." (defun auto-show-mode (arg)
(interactive) "Turn automatic horizontal scroll mode on or off.
(setq auto-show-enable (not auto-show-enable))) With arg, turn auto scrolling on if arg is positive, off otherwise."
(interactive "P")
(setq auto-show-mode
(if (null arg)
(not auto-show-mode)
(> (prefix-numeric-value arg) 0))))
(defun auto-show-make-point-visible (&optional ignore-arg) (defun auto-show-make-point-visible (&optional ignore-arg)
"Scrolls the screen horizontally to make point visible but only if "Scroll horizontally to make point visible, if that is enabled.
auto-show-enable is non-nil and lines are truncated. See also variable This function only does something if `auto-show-mode' is non-nil
`auto-show-enable' and command `auto-show-toggle'." and longlines are being truncated in the selected window.
See also the command `auto-show-toggle'."
(interactive) (interactive)
(if (and auto-show-enable (auto-show-truncationp) (if (and auto-show-mode (auto-show-truncationp)
(equal (window-buffer) (current-buffer))) (equal (window-buffer) (current-buffer)))
(let* ((col (current-column)) ;column on line point is at (let* ((col (current-column)) ;column on line point is at
(scroll (window-hscroll)) ;how far window is scrolled (scroll (window-hscroll)) ;how far window is scrolled
...@@ -146,15 +101,13 @@ auto-show-enable is non-nil and lines are truncated. See also variable ...@@ -146,15 +101,13 @@ auto-show-enable is non-nil and lines are truncated. See also variable
) )
) )
(defun auto-show-comint-make-point-visible () ;; Do auto-scrolling after commands.
"Add a function to comint-output-filter-functions that auto-scrolls (add-hook 'post-command-hook 'auto-show-make-point-visible)
left or right on output to the buffer.
NOTE: you should load comint mode before this as comint.el uses a ;; Do auto-scrolling in comint buffers after process output also.
defvar to initialize comint-output-filter-functions to the default value." (add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t)
(interactive)
(add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t) (provide 'auto-show)
)
;; end of auto-show.el ;; auto-show.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment