【问题标题】:Vertical padding or margin on emacs bufferemacs 缓冲区上的垂直填充或边距
【发布时间】:2014-07-30 15:20:28
【问题描述】:

似乎有过多的 emacs 模式可用于添加水平填充(请参阅 https://github.com/ikame/centered-window-mode ),但没有用于垂直填充。

我希望能够指定一个高度来填充 emacs 缓冲区的顶部和底部。我的动机是在全屏模式下进行截屏和演示,因为投影仪可能无法显示该内容,因此处于最顶部或最底部可能会出现问题。

【问题讨论】:

  • 这里是一个相关的线程:stackoverflow.com/a/12632805/2112489 建议类似:(set-frame-parameter nil 'internal-border-width 10)
  • 谢谢,遗憾的是,Mac 上的全屏仅填充顶部和左侧。 (全屏时我想要它)
  • 这里有两个思路:(1)另外创建两个窗口,一个在上面,一个在下面,并使非活动模式行不可见(例如,非活动模式行的文本和背景可以匹配默认缓冲区背景颜色),没有标题;或者,(2)创建一个次要模式,在window-startwindow-end 之前的一定数量的行处插入一个不可见的间隔覆盖。这是一个包含次要模式的线程的链接,用于演示在 redisplay 发生之前计算 new window-startwindow-endstackoverflow.com/a/24216247/2112489

标签: emacs elisp emacs24


【解决方案1】:

这是我上面的 cmets 中提到的概念之一的示例。此示例在工作窗口上方创建一个窗口,在工作窗口下方创建一个窗口——顶部/底部窗口有不可见的inactive 模式行,并且没有右滚动条,cursor-typenil。 alist 窗口高度可以在名为screencast-function 的函数内手动调整。

(defun lawlist-split-below (buffer alist)
  (let ((window (split-window (selected-window) nil 'below)))
    (window--display-buffer buffer window
      'window alist display-buffer-mark-dedicated)))

(defun lawlist-split-above (buffer alist)
  (let ((window (split-window (selected-window) nil 'above)))
    (window--display-buffer buffer window
      'window alist display-buffer-mark-dedicated)))

(defun screencast-function ()
(interactive)
  (toggle-frame-fullscreen)
  (set-face-attribute 'default nil
    :background "black" :foreground "white" :font "Courier" :height 180)
  (set-face-attribute 'mode-line nil
    :height 140 :foreground "black" :background "#eab700" :box nil)
  (set-face-attribute 'mode-line-inactive nil
    :height 140 :foreground "black" :background "black" :box nil)
  (lawlist-split-below (get-buffer-create "foo") '((window-height . 2)))
  (with-current-buffer (get-buffer "foo")
    (setq cursor-type nil))
  (set-window-scroll-bars (get-buffer-window "foo") 0 'right nil)
  (lawlist-split-above (get-buffer-create "bar") '((window-height . 2)))
  (with-current-buffer (get-buffer "bar")
    (setq cursor-type nil))
  (set-window-scroll-bars (get-buffer-window "bar") 0 'right nil) )

【讨论】:

    【解决方案2】:

    初稿(2014 年 7 月 30 日):此示例在可见窗口的开头和结尾处创建了一个不可见的覆盖间隔。然而,模式线仍处于最底部。某些使用覆盖的模式可能与此示例不兼容。要查看此示例的实际效果,只需输入 M-x screencast-mode

    (defun screencast-function
      (&optional
        screencast-old-window-start
        screencast-old-window-end
        screencast-old-window-end-forced
        screencast-new-window-start
        screencast-new-window-end)
      (save-excursion
        (let* (
            (window-start
              (cond
                (screencast-old-window-start
                  screencast-old-window-start)
                (screencast-new-window-start
                  screencast-new-window-start)
                (t (window-start))))
            (window-end
              (cond
                ((and
                    screencast-old-window-end
                    screencast-old-window-end-forced
                    (= screencast-old-window-end screencast-old-window-end-forced))
                  screencast-old-window-end)
                ((and
                    screencast-old-window-end
                    screencast-old-window-end-forced
                    (> screencast-old-window-end-forced screencast-old-window-end))
                  screencast-old-window-end-forced)
                (screencast-new-window-end
                  screencast-new-window-end)
                (t (window-end (selected-window) t))))
            (top-margin 5)
            (bottom-margin 5)
            end-point
            (top-margin-overlay
              (propertize (char-to-string ?\uE001)
                'display `((space :align-to 0 :height ,top-margin))))
            (bottom-margin-overlay
              (propertize (char-to-string ?\uE001)
                'display `((space :align-to 0 :height ,bottom-margin)))) )
          (screencast-delete-overlays (point-min) (point-max))
          (setq top-margin-overlay-string top-margin-overlay)
          (setq bottom-margin-overlay-string bottom-margin-overlay)
          (overlay-put (make-overlay window-start window-start)
            'before-string top-margin-overlay)
          (setq window-end (window-end nil t))
          (goto-char window-end)
          (vertical-motion (- 2 bottom-margin))
          (setq end-point (point))
          (overlay-put (make-overlay end-point end-point)
            'before-string bottom-margin-overlay)
          (setq screencast-overlays-exist-p t) )))
    
    (defun screencast-remove-overlays (beg end name val)
      "Remove the overlays."
         ;; DEBUGGING
      ;; (unless (and beg end name val)
      ;;   (message "ERROR -- beg:  %s | end:  %s | name:  %s | val:  %s" beg end name val))
      (when (and beg end name val)
        (overlay-recenter end)
        (dolist (o (overlays-in beg end))
          (when (eq (overlay-get o name) val)
            (delete-overlay o)))))
    
    (defun screencast-delete-overlays (start end)
    "Delete overlays from `start` to `end`."
      (when screencast-overlays-exist-p
        (dolist (ov `(
            ,top-margin-overlay-string
            ,bottom-margin-overlay-string  ))
        (screencast-remove-overlays start end 'before-string ov)) 
        (setq screencast-overlays-exist-p nil)))
    
    (defvar top-margin-overlay-string nil
    "This local variable stores the `top-margin-overlay-string`.")
    (make-variable-buffer-local 'top-margin-overlay-string)
    
    (defvar bottom-margin-overlay-string nil
    "This local variable stores the `bottom-margin-overlay-string`.")
    (make-variable-buffer-local 'bottom-margin-overlay-string)
    
    (defvar screencast-overlays-exist-p nil
    "A simple test for the existence of screencast overlays.")
    (make-variable-buffer-local 'screencast-overlays-exist-p)
    
    (defvar screencast-old-window-start nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'screencast-old-window-start)
    
    (defvar screencast-old-window-end nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'screencast-old-window-end)
    
    (defvar screencast-old-window-end-forced nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'screencast-old-window-end-forced)
    
    (defvar screencast-new-window-start nil
    "This local variable is set within the `window-scroll-functions`.")
    (make-variable-buffer-local 'screencast-new-window-start)
    
    (defvar screencast-new-window-end nil
    "This local variable is set within the `window-scroll-functions`.")
    (make-variable-buffer-local 'screencast-new-window-end)
    
    (defun screencast-post-command-hook ()
    "NOT good for things like: `beginning-of-buffer`; `end-of-buffer`; `yank`; etc.
    NOTE:  When using `this-command` in conjunction with the `post-command-hook`,
    the `window-scroll-functions` hook would need to use `last-command`."
      (when
          (and
            (not (minibufferp))
            (window-live-p (get-buffer-window (current-buffer))))
        (setq screencast-old-window-start (window-start))
        (setq screencast-old-window-end (window-end))
        (setq screencast-old-window-end-forced (window-end nil t))
        (when
            (or
              (and
                (not (< (point) screencast-old-window-start))
                (not (> (point) screencast-old-window-end))
                (not (> (point) screencast-old-window-end-forced)))
              ;; special situation when deleting region greater than size of window.
              (and
                (region-active-p)
                (< screencast-old-window-end 0))
              ;; special situation when deleting region greater than size of window.
              (and
                (region-active-p)
                (> (point) screencast-old-window-start)
                (> (point) screencast-old-window-end)
                (< (point) screencast-old-window-end-forced)) )
          (screencast-function screencast-old-window-start screencast-old-window-end screencast-old-window-end-forced nil nil) )))
    
    (defun screencast-window-scroll-functions (win _start)
    "Good for things like: `beginning-of-buffer`; `end-of-buffer`; `yank`; etc.
    NOTE:  When using `this-command` in conjunction with the `post-command-hook`,
    the `window-scroll-functions` hook would need to use `last-command`."
      (when
          (and
            screencast-old-window-start
            screencast-old-window-end
            screencast-old-window-end-forced
            (not (minibufferp))
            (window-live-p (get-buffer-window (current-buffer))))
        (when
            (or
              (not (= _start screencast-old-window-start))
              (< (point) screencast-old-window-start)
              (> (point) screencast-old-window-end)
              (> (point) screencast-old-window-end-forced))
          (setq screencast-new-window-start _start)
          (setq screencast-new-window-end (window-end win t))
          (screencast-function nil nil nil screencast-new-window-start screencast-new-window-end)
          (setq screencast-old-window-start nil)
          (setq screencast-old-window-end nil)
          (setq screencast-old-window-end-forced nil))))
    
    (define-minor-mode screencast-mode
    "A minor-mode for screencasts."
      :init-value nil
      :lighter " screencast"
      :keymap nil
      :global nil
      :group nil
      (cond
        (screencast-mode
          (condition-case error
            (progn
              (setq scroll-conservatively 101)
              (add-hook 'post-command-hook 'screencast-post-command-hook nil t)
              (add-hook 'window-scroll-functions 'screencast-window-scroll-functions nil t)
              (message "Turned ON `screencast-mode`."))
            (error
             (screencast-mode 0)
             (signal (car error) (cdr error)))))
        ((not screencast-mode)
          (remove-hook 'post-command-hook 'screencast-post-command-hook t)
          (remove-hook 'window-scroll-functions 'screencast-window-scroll-functions t)
          (screencast-delete-overlays (point-min) (point-max))
          (message "Turned OFF `screencast-mode`.") )))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    

    【讨论】:

      【解决方案3】:

      我创建了一个与此相关的次要模式,现在可以在 MELPA 上使用:

      TopSpace - 在 Emacs 中向下滚动并重新定位顶部行/获取上边距/填充

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-10
        • 2011-03-24
        • 1970-01-01
        • 2010-10-08
        • 1970-01-01
        • 1970-01-01
        • 2013-12-08
        相关资源
        最近更新 更多