home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / alt / lucidem / help / 838 < prev    next >
Encoding:
Text File  |  1993-01-05  |  9.2 KB  |  231 lines

  1. x-gateway: rodan.UU.NET from help-lucid-emacs to alt.lucid-emacs.help; Tue, 5 Jan 1993 09:48:55 EST
  2. From: amir@matis.ingr.com (Amir J Katz)
  3. Message-ID: <9301051433.AA09984@simpson.ingr.com>
  4. Subject: scroll-in-place
  5. Organization: SEE Technologies Ltd.
  6. Reply-To: amir@matis.ingr.com
  7. X-Mailer: ELM [version 2.3 PL11]
  8. Date: Tue, 5 Jan 1993 14:48:57 GMT
  9. Newsgroups: alt.lucid-emacs.help
  10. Path: sparky!uunet!wendy-fate.uu.net!help-lucid-emacs
  11. Sender: help-lucid-emacs-request@lucid.com
  12. Lines: 217
  13.  
  14. Four years ago, an excellent package was posted to gnu.emacs.sources by Joe
  15. Wells, then at Boston U, which solves the problem of scroll-page up/down not
  16. returning to the same point. It works fine under emacs 18.x.
  17.  
  18. However, Under Lucid 19.3, using these modified scroll up/down functions
  19. destroys the mark. Thus, when copying areas spanning more than a screenful,
  20. the generic C-v/M-v must again be used.
  21.  
  22. Has anyone fixed that for Lucid Emacs? This is way above my lisp skills.
  23. I'm enclosing the package below, so a kind soul may modify it for lemacs.
  24.  
  25. TIA,
  26.     Amir
  27.  
  28. ;; Date-Received: 3 Dec 88 16:05:14 GMT
  29. ;; Reply-To: jbw@bucsf.bu.edu (Joe Wells)
  30. ;; Organization: Boston Univ Comp. Sci.
  31. ;; 
  32. ;; Here are improved scrolling commands for GNU Emacs.  The functions
  33. ;; here can effectively replace scroll-up and scroll-down.
  34. ;; 
  35. ;; They provide a superior scrolling capability, because all scrolling
  36. ;; actions are now completely reversible.  By reversible, I mean that by
  37. ;; using only prefix arguments and the scrolling commands, you can return
  38. ;; the screen and the point to the *exact* original configuration it was
  39. ;; in before you started scrolling.
  40. ;; 
  41. ;; These scrolling commands keep point on the same line of the screen,
  42. ;; and on (or near) the same column.
  43. ;; 
  44. ;; If a scrolling action is given a numeric argument, it will use that as
  45. ;; the distance to scroll.  Immediately subsequent scrolling actions
  46. ;; without arguments will use the same distance.
  47. ;; 
  48. ;; When near the beginning or end of a buffer, these commands will
  49. ;; remember that the last scrolling action they did was not a complete
  50. ;; scroll, and will reverse it properly.
  51. ;; 
  52. ;; The replacement for scroll-up will avoid leaving blank-space past the
  53. ;; end of the buffer on the screen, except when necessary to make a
  54. ;; previous scrolling action reversible.
  55. ;; 
  56. ;; So, put these in a file, bind to keys of your choice, and enjoy!
  57. ;; 
  58. ;; --
  59. ;; Joe Wells
  60. ;; INTERNET: jbw%bucsf.bu.edu@bu-it.bu.edu
  61. ;; UUCP: ...!harvard!bu-cs!bucsf!jbw
  62. ;; 
  63. ;; -------------------------------cut here---------------------------------
  64. ;; Improved window scrolling commands.
  65. ;; Copyright (C) 1988 Free Software Foundation, Inc.
  66.  
  67. ;; This file is not officially part of GNU Emacs, but is being donated
  68. ;; to the Free Software Foundation.
  69.  
  70. ;; GNU Emacs is distributed in the hope that it will be useful,
  71. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  72. ;; accepts responsibility to anyone for the consequences of using it
  73. ;; or for whether it serves any particular purpose or works at all,
  74. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  75. ;; License for full details.
  76.  
  77. ;; Everyone is granted permission to copy, modify and redistribute
  78. ;; GNU Emacs, but only under the conditions described in the
  79. ;; GNU Emacs General Public License.   A copy of this license is
  80. ;; supposed to have been given to you along with GNU Emacs so you
  81. ;; can know your rights and responsibilities.  It should be in a
  82. ;; file named COPYING.  Among other things, the copyright notice
  83. ;; and this notice must be preserved on all copies.
  84.  
  85. ;; Author: Joe Wells
  86. ;; jbw%bucsf.bu.edu@bu-it.bu.edu (school year)
  87. ;; joew%uswest@boulder.colorado.edu (summer)
  88.  
  89. ;; The ideas for this package were derived from the C code in
  90. ;; src/window.c and elsewhere.  The names of the functions conflict
  91. ;; with names in lisp/term/sun.el.  If someone can think of better
  92. ;; names, send me a suggestion.  The functions in this file should
  93. ;; always be byte-compiled for speed.  The functions really don't know
  94. ;; what to do with an argument of '-, which results from C-u - or ESC
  95. ;; -.  I could use some suggestions on that also.
  96.  
  97. (require 'backquote)
  98.  
  99. (defmacro abs (n)
  100.   (`(let ((m (, n)))
  101.       (if (< m 0) (- m) m))))
  102.  
  103. (defmacro same-sign (x y)
  104.   (`(let ((z (, y)))
  105.      (if (< (, x) 0)
  106.      (< z 0) (>= z 0)))))
  107.  
  108. (defvar sip:goal-column 0
  109.   "Current goal column for scrolling motion.  It is the column where
  110. point was at the start of current run of scrolling commands.")
  111.  
  112. (defvar sip:default-motion nil
  113.   "Default argument to scroll-up-in-place or scroll-down-in-place,
  114. when repeated with no intervening command and no argument.  This is
  115. the last argument used.")
  116.  
  117. (defvar sip:eob-motion nil
  118.   "Amount of motion to be used by scroll-up-in-place or
  119. scroll-down-in-place when repeated after hitting the end/beginning of
  120. the buffer with no intervening command and no argument.  This is the
  121. amount of vertical motion that was actually done on the last scroll
  122. operation (which was less than requested, because of buffer
  123. boundaries).")
  124.  
  125. (defvar sip:eob-blank-limit nil
  126.   "This is the minimum amount of text that is required on the last
  127. screen.  scroll-up-in-place will refuse to scroll any more than this.
  128. Normally this is one less than the number of text line in the window.
  129. However, if a sequence of scrolling commands starts with less text on
  130. the last screen, this is remembered here.")
  131.  
  132. (defun scroll-down-in-place (n)
  133.   "Scroll text of current window downward ARG lines; or near full screen if
  134. no ARG.  When calling from a program, supply a number as argument or nil.
  135. Leaves point in same row and column of window."
  136.   (interactive "P")
  137.   (scroll-in-place-command n -1)
  138.   nil)
  139.  
  140. (defun scroll-up-in-place (n)
  141.   "Scroll text of current window upward ARG lines; or near full screen if
  142. no ARG.  When calling from a program, supply a number as argument or nil.
  143. Leaves point in same row and column of window."
  144.   (interactive "P")
  145.   (scroll-in-place-command n 1)
  146.   nil)
  147.  
  148. (defun scroll-in-place-command (arg direction)
  149.   "Scroll text of current window ARG lines in DIRECTION direction.  If ARG
  150. is null, scrolls almost entire window.  If ARG is '-, scrolls window in
  151. - DIRECTION direction.  DIRECTION is either 1 or -1.  Leaves point in same
  152. row and column of window."
  153.   ;;  (message "%s %s %s %s %s %s"
  154.   ;;       last-command this-command arg sip:default-motion
  155.   ;;       sip:eob-motion sip:eob-blank-limit)
  156.   (let* ((window (selected-window))
  157.      (height (- (window-height window)
  158.             (if (eq window (minibuffer-window)) 0 1)))
  159.      (lines (- height next-screen-context-lines))
  160.      (n (prefix-numeric-value arg))
  161.      (first-scroll
  162.       (not (memq last-command '(scroll-down-in-place scroll-up-in-place))))
  163.      moved)
  164.     ;; Barf on zero argument
  165.     (and (numberp arg) (zerop arg) (while t (signal 'args-out-of-range arg)))
  166.     ;; Figure out how much vertical motion to use.  An explicit argument
  167.     ;; is always given precedence.  If a immediately prior scroll ran
  168.     ;; into a buffer boundary, and didn't go full distance, and this is
  169.     ;; a scroll in the opposite direction, go back the amount last
  170.     ;; traveled.  (Man is that a confusing sentence!)  Otherwise, if
  171.     ;; following a prior scroll use the last explicit argument.
  172.     (cond ((or (numberp arg) (consp arg))
  173.        (setq sip:default-motion n)
  174.        (setq sip:eob-motion nil)
  175.        (setq lines n))
  176.       ((eq arg '-)            ;needs more work
  177.        (setq lines (- lines)))
  178.       (first-scroll
  179.        (setq sip:default-motion lines)
  180.        (setq sip:eob-motion nil))
  181.       ((and sip:eob-motion
  182.         (not (same-sign direction sip:eob-motion)))
  183.        (setq lines (abs sip:eob-motion))
  184.        (setq sip:eob-motion nil))
  185.       (t                ;in sequence w/o arg ...
  186.        (setq lines sip:default-motion)))
  187.     (cond (first-scroll
  188.        (setq sip:goal-column (or (and track-eol (eolp) 9999)
  189.                           (current-column)))
  190.        (setq sip:eob-blank-limit
  191.          (save-excursion
  192.            (goto-char (window-start window))
  193.            (vertical-motion (1- height))))))
  194.     (setq lines (* direction lines))
  195.     ;; if point not in window, center window around point
  196.     (save-excursion
  197.       (cond ((not (pos-visible-in-window-p (point) window))
  198.          (vertical-motion (/ (- height) 2))
  199.          (set-window-start window (point)))))
  200.     (catch 'foo
  201.       (save-excursion
  202.     (goto-char (window-start window))
  203.     (cond ((< lines 0)        ; upward -- scrolling down
  204.            (cond ((bobp)
  205.               (ding)
  206.               (message (get 'beginning-of-buffer 'error-message))
  207.               (throw 'foo nil)))
  208.            (setq moved (vertical-motion lines)))
  209.           ((> lines 0)        ; downward -- scrolling up
  210.            (setq moved (+ (vertical-motion (+ lines sip:eob-blank-limit))
  211.                   (vertical-motion (- sip:eob-blank-limit))))
  212.            (cond ((< moved 1)
  213.               (ding)
  214.               (message (get 'end-of-buffer 'error-message))
  215.               (throw 'foo nil))))
  216.           (t (error "Impossible zero value")))
  217.     (set-window-start window (point)))
  218.       (if (< (abs moved) (abs lines))
  219.       (setq sip:eob-motion moved))
  220.       (vertical-motion moved)))        ;keep point on same window line
  221.   (move-to-column sip:goal-column))
  222.  
  223. (provide 'scroll-in-place)
  224.  
  225. -- 
  226. /* ----------------------------------------------------------- */
  227. /*  Amir J. Katz             |   amir@matis.ingr.COM           */
  228. /*  System Specialist        |   Voice:  +972 52-584684        */
  229. /*  SEE Technologies Ltd.    |   Fax:    +972 52-543917        */
  230. /*  ....... To Boldly Go Where No One Has Hacked Before....... */
  231.