Emacs: scroll buffer not point

后端 未结 5 1046
心在旅途
心在旅途 2020-12-28 16:53

Is it possible to scroll the entire visible portion of the buffer in Emacs, but leave point where it is. Example: point is towards the bottom of the window and I want to see

相关标签:
5条回答
  • 2020-12-28 17:30

    This might be of use. According to the EmacsWiki page on Scrolling;

    The variable scroll-preserve-screen-position may be useful to some. When you scroll down, and up again, point should end up at the same position you started out with. The value can be toggled by the built in mode M-x scroll-lock-mode.

    0 讨论(0)
  • 2020-12-28 17:33

    I think this is better:

    (defun gcm-scroll-down ()
          (interactive)
          (scroll-up 1))
        (defun gcm-scroll-up ()
          (interactive)
          (scroll-down 1))
        (global-set-key [(control down)] 'gcm-scroll-down)
        (global-set-key [(control up)]   'gcm-scroll-up)
    

    reference : emacs wiki

    0 讨论(0)
  • 2020-12-28 17:36
    ;; Preserve the cursor position relative to the screen when scrolling
    (setq scroll-preserve-screen-position 'always)
    
    ;; Scroll buffer under the point
    ;; 'scroll-preserve-screen-position' must be set to a non-nil, non-t value for
    ;; these to work as intended.
    (global-set-key (kbd "M-p") #'scroll-down-line)
    (global-set-key (kbd "M-n") #'scroll-up-line)
    
    0 讨论(0)
  • 2020-12-28 17:39
    ;;;_*======================================================================
    ;;;_* define a function to scroll with the cursor in place, moving the
    ;;;_* page instead
    ;; Navigation Functions
    (defun scroll-down-in-place (n)
      (interactive "p")
      (previous-line n)
      (unless (eq (window-start) (point-min))
        (scroll-down n)))
    
    (defun scroll-up-in-place (n)
      (interactive "p")
      (next-line n)
      (unless (eq (window-end) (point-max))
        (scroll-up n)))
    
    (global-set-key "\M-n" 'scroll-up-in-place)
    (global-set-key "\M-p" 'scroll-down-in-place)
    
    0 讨论(0)
  • 2020-12-28 17:44

    try these. Change M-n and M-p key bindings according to your taste

    ;;; scrollers
    (global-set-key "\M-n" "\C-u1\C-v")
    (global-set-key "\M-p" "\C-u1\M-v")
    
    0 讨论(0)
提交回复
热议问题