如何在组织模式下使内联图像负责?

Lor*_*lor 5 emacs org-mode

当我切换内嵌图像使用时org-toggle-inline-images,显示图像.但是,当图像太大时,它会溢出编辑器的框架(见下面的截图).

在此输入图像描述

如何使图像负责,这意味着图像的最大尺寸不应超过窗口大小的宽度.

当然,我可以使用下面的代码来修复图像的大小.但我真正想要的是某种响应式图像显示.

(setq org-mode-actual-width 600)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

感谢您抽出时间查看此问题.

Wil*_*iam 6

每当使用钩子调整窗口大小时,下面的函数都会重新渲染组织模式内联图像。仅当窗口显示少于 80 列(通常为屏幕的 1/3)时,它才会缩小图像。我相信它比总是以窗口宽度渲染效果更好。

(defun org-image-resize (frame)
  (when (derived-mode-p 'org-mode)
      (if (< (window-total-width) 80)
      (setq org-image-actual-width (window-pixel-width))
    (setq org-image-actual-width (* 80 (window-font-width))))
      (org-redisplay-inline-images)))

(add-hook 'window-size-change-functions 'org-image-resize)
Run Code Online (Sandbox Code Playgroud)

上面代码的 GIF 演示

如果您希望图像与窗口宽度大小匹配:

(defun org-image-resize (frame)
  (when (derived-mode-p 'org-mode)
      (setq org-image-actual-width (window-pixel-width))
      (org-redisplay-inline-images)))

(add-hook 'window-size-change-functions 'org-image-resize)
Run Code Online (Sandbox Code Playgroud)

或者如果您想要右侧有一些边距,则将其更改(window-pixel-width)为。(- (window-pixel-width) 20)


Dom*_*mpf 5

来自以下文件org-image-actual-width:

Documentation:
Should we use the actual width of images when inlining them?

When set to t, always use the image width.

When set to a number, use imagemagick (when available) to set
the image's width to this value.

When set to a number in a list, try to get the width from any
#+ATTR.* keyword if it matches a width specification like

  #+ATTR_HTML: :width 300px

and fall back on that number if none is found.

When set to nil, try to get the width from an #+ATTR.* keyword
and fall back on the original width if none is found.
Run Code Online (Sandbox Code Playgroud)

因此,您可以使用属性#+ ATTR_HTML来指定宽度.必须手动指定它.这是否足够响应?