branch: externals/org-remark commit 89ee82935ca9eb68535b4b05d63a4fe0292ca7d8 Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
fix: window margins do not persist Adapt the way Olivetti does it. --- org-remark-line.el | 59 +++++++++++++++++++++++++++++++++++++++++------------- org-remark.el | 2 ++ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/org-remark-line.el b/org-remark-line.el index 93b118f857..9e3ad39c51 100644 --- a/org-remark-line.el +++ b/org-remark-line.el @@ -45,6 +45,47 @@ (defvar org-remark-line-ellipsis "…") +;;;###autoload +(define-minor-mode org-remark-line-mode + "Enable Org-remark to highlight and annotate the whole line." + :global nil + :group 'org-remark + (if org-remark-line-mode + ;; Enable + (progn + ;; Depth is deeper than the default one for range highlight. + ;; This is to prioritize it over line-highlight when the fomer + ;; is at point and yet on the same line of another + ;; line-highlight. + (add-hook 'org-remark-find-dwim-functions + #'org-remark-line-find 80 :local) + (add-hook 'window-size-change-functions + #'org-remark-line-set-window-margins nil :local) + ;; (add-hook 'text-scale-mode-hook + ;; #'org-remark-line-set-buffer-windows nil :local) + (org-remark-line-set-buffer-windows)) + (remove-hook 'org-remark-find-dwim-functions #'org-remark-line-find :local) + (remove-hook 'window-size-change-functions + #'org-remark-line-set-window-margins :local) + (remove-hook 'text-scale-mode-hook + #'org-remark-line-set-buffer-windows :local))) + +(defun org-remark-line-set-buffer-windows () + " +Adapted from Olivetti mode" + (mapc #'org-remark-line-set-window-margins + (get-buffer-window-list nil nil 'visible))) + +(defun org-remark-line-set-window-margins (window-or-frame) + "Set the margins of current window that displays current buffer. +Return a cons of the form (LEFT-WIDTH . RIGHT-WIDTH). If a +marginal area does not exist, its width will be returned as nil." + (when (and (windowp window-or-frame) org-remark-line-mode) + (cl-destructuring-bind (left-width . right-width) (window-margins) + (when (or (eq left-width nil) (< left-width 3)) + (set-window-margins nil 3)) + (window-margins)))) + (defun org-remark-line-pos-bol (pos) "Return the beginning of the line position for POS." (save-excursion @@ -66,14 +107,6 @@ by `overlays-in'." (highlights (overlays-in bol bol))) (seq-find #'org-remark-line-highlight-p highlights))) -;; Depth is deeper than the default one for range highlight. This is to -;; prioritize it over line-highlight when the fomer is at point and yet -;; on the same line of another line-highlight. -(add-hook 'org-remark-find-dwim-functions #'org-remark-line-find 80) - -(add-hook 'window-size-change-functions - #'(lambda (&rest args) - (set-window-margins nil 2))) ;;;###autoload ;; (defun org-remark-mark-line (beg end &optional id mode) @@ -100,13 +133,11 @@ by `overlays-in'." (defun org-remark-line-highlight-overlay-put (ov face &optional string) (let* ((face (or face 'org-remark-line-highlighter)) - (left-margin (or (car (window-margins)) - ;; when nil = no margin, set to 1 - (progn (set-window-margins nil 2) - 2))) - (spaces (- left-margin 2)) + (left-margin (car (org-remark-line-set-window-margins + (get-buffer-window)))) + ;;(spaces (- left-margin 1)) (string (or string - (with-temp-buffer (insert-char ?\s spaces) + (with-temp-buffer ;;(insert-char ?\s spaces) (insert org-remark-line-icon) (buffer-string))))) (overlay-put ov 'before-string (propertize "! " 'display diff --git a/org-remark.el b/org-remark.el index 84679aabcf..6b5e95dcc9 100644 --- a/org-remark.el +++ b/org-remark.el @@ -315,6 +315,7 @@ recommended to turn it on as part of Emacs initialization. (org-remark-mode ;; Activate (org-remark-icon-mode +1) ;; automatically enabled by default + (org-remark-line-mode +1) (org-remark-highlights-load) (add-hook 'after-save-hook #'org-remark-save nil t) (add-hook 'org-remark-highlight-link-to-source-functions @@ -328,6 +329,7 @@ recommended to turn it on as part of Emacs initialization. (delete-overlay highlight))) (setq org-remark-highlights nil) (org-remark-icon-mode -1) + (org-remark-line-mode -1) (remove-hook 'after-save-hook #'org-remark-save t) (remove-hook 'org-remark-highlight-link-to-source-functions #'org-remark-highlight-link-to-source-default)