view lisp/auto-show.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128

typos.
author Jeff Law <law@redhat.com>
date Wed, 10 Sep 1997 21:16:20 +0000
parents 8134c62c03d0
children 93652fd3234d
line wrap: on
line source

;;; auto-show.el --- perform automatic horizontal scrolling as point moves
;;; This file is in the public domain.

;;; Keywords: scroll display minor-mode
;;; Author: Pete Ware <ware@cis.ohio-state.edu>
;;; Maintainer: FSF

;;; Commentary:

;;; This file provides functions that
;;; automatically scroll the window horizontally when the point moves
;;; off the left or right side of the window.

;;; Once this library is loaded, automatic horizontal scrolling
;;; occurs whenever long lines are being truncated.
;;; To request truncation of long lines, set the variable
;;; Setting the variable `truncate-lines' to non-nil.
;;; You can do this for all buffers as follows:
;;;
;;; (set-default 'truncate-lines t)

;;; Here is how to do it for C mode only:
;;;
;;; (set-default 'truncate-lines nil)	; this is the original value
;;; (defun my-c-mode-hook ()
;;;   "Run when C-mode starts up.  Changes ..."
;;;   ... set various personal preferences ...
;;;   (setq truncate-lines t))
;;; (add-hook 'c-mode-hook 'my-c-mode-hook)
;;;
;;;
;;; As a finer level of control, you can still have truncated lines but
;;; without the automatic horizontal scrolling by setting the buffer
;;; local variable `auto-show-mode' to nil.  The default value is t.
;;; The command `auto-show-mode' toggles the value of the variable
;;; `auto-show-mode'.

;;; Code:

(defvar auto-show-mode t
  "*Non-nil enables automatic horizontal scrolling, when lines are truncated.
The default value is t.  To change the default, do this:
	(set-default 'auto-show-mode nil)
See also command `auto-show-mode'.
This variable has no effect when lines are not being truncated.
This variable is automatically local in each buffer where it is set.")

(make-variable-buffer-local 'auto-show-mode)

(defvar auto-show-shift-amount 8 
  "*Extra columns to scroll. for automatic horizontal scrolling.")

(defvar auto-show-show-left-margin-threshold 50
  "*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.")

(defun auto-show-truncationp ()
  "True if line truncation is enabled for the selected window."
  (or truncate-lines 
      (and truncate-partial-width-windows
	   (< (window-width) (frame-width)))))

;;;###autoload
(defun auto-show-mode (arg)
  "Turn automatic horizontal scroll mode on or off.
With arg, turn auto scrolling on if arg is positive, off otherwise.
This mode is enabled or disabled for each buffer individually.
It takes effect only when `truncate-lines' is non-nil."
  (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)
  "Scroll horizontally to make point visible, if that is enabled.
This function only does something if `auto-show-mode' is non-nil
and longlines are being truncated in the selected window.
See also the command `auto-show-mode'."
  (interactive)
  (if (and auto-show-mode (auto-show-truncationp)
	   (equal (window-buffer) (current-buffer)))
      (let* ((col (current-column))	;column on line point is at
	     (scroll (window-hscroll))	;how far window is scrolled
	     (w-width (- (window-width) 
			 (if (> scroll 0)
			     2 1)))	;how wide window is on the screen
	     (right-col (+ scroll w-width)))
	(if (and (< col auto-show-show-left-margin-threshold)
		 (< col (window-width))
		 (> scroll 0))
	    (scroll-right scroll)
	  (if (< col scroll)		;to the left of the screen
	      (scroll-right (+ (- scroll col) auto-show-shift-amount))
	    (if (or (> col right-col)	;to the right of the screen
		    (and (= col right-col)
			 (not (eolp))))
		(scroll-left (+ auto-show-shift-amount 
				(- col (+ scroll w-width))))
	      )
	    )
	  )
	)
    )
  )

;; Do auto-scrolling after commands.
(add-hook 'post-command-hook 'auto-show-make-point-visible)

;; Do auto-scrolling in comint buffers after process output also.
(add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t)

(provide 'auto-show)

;; auto-show.el ends here