Add aspect ratio check for centering.

Fix git conflict.
minor improvements and cleanup.
This commit is contained in:
JAremko 2016-08-16 19:18:56 +03:00 committed by Eivind Fonn
parent 7140e8dfa8
commit 328c6b81aa
3 changed files with 62 additions and 54 deletions

View File

@ -521,13 +521,12 @@ You can modify the list of visual enhancements applied by the =space-doc-mode=:
org-indent-mode org-indent-mode
view-mode view-mode
hide-line-numbers hide-line-numbers
emphasis-overlays alternative-emphasis
meta-tags-overlays alternative-tags-look
link-protocol link-protocol
org-block-line-face-remap org-block-line-face-remap
org-kbd-face-remap org-kbd-face-remap
resize-inline-images resize-inline-images))
advice-org-do-emphasis-faces))
#+END_SRC #+END_SRC
It's the default value of the variable with all enhancements. It's the default value of the variable with all enhancements.

View File

@ -120,12 +120,12 @@ Assume to be called interactively when INTERACT has non nil value."
(face-remap-add-relative 'fringe :background (face-remap-add-relative 'fringe :background
spacemacs-centered-buffer-mode-fringe-color) spacemacs-centered-buffer-mode-fringe-color)
(set-window-buffer window indirect-buffer) (set-window-buffer window indirect-buffer)
(advice-add 'spacemacs/previous-useful-buffer (advice-add 'previous-buffer
:before :before
#'spacemacs//centered-buffer-mode-prev-next-useful-buffer-advice) #'spacemacs//centered-buffer-mode-prev-next-buffer-advice)
(advice-add 'spacemacs/next-useful-buffer (advice-add 'next-buffer
:before :before
#'spacemacs//centered-buffer-mode-prev-next-useful-buffer-advice) #'spacemacs//centered-buffer-mode-prev-next-buffer-advice)
(add-hook 'buffer-list-update-hook (add-hook 'buffer-list-update-hook
'spacemacs//centered-buffer-buffer-list-update-fringes) 'spacemacs//centered-buffer-buffer-list-update-fringes)
(add-hook 'window-configuration-change-hook (add-hook 'window-configuration-change-hook
@ -138,16 +138,15 @@ Assume to be called interactively when INTERACT has non nil value."
(when interact (when interact
(message "Not enough space to center the buffer!")))))))) (message "Not enough space to center the buffer!"))))))))
(defun spacemacs//centered-buffer-mode-prev-next-useful-buffer-advice () (defun spacemacs//centered-buffer-mode-prev-next-buffer-advice ()
"Disables `spacemacs-centered-buffer-mode' when `spacemacs/previous-useful-buffer' "Disables `spacemacs-centered-buffer-mode' when `spacemacs/previous-buffer'
or `spacemacs/next-useful-buffer' is called. It's better than flagging the original or `spacemacs/next-buffer' is called."
buffer as 'unuseful'."
(when (bound-and-true-p spacemacs-centered-buffer-mode) (when (bound-and-true-p spacemacs-centered-buffer-mode)
(spacemacs-centered-buffer-mode -1))) (spacemacs-centered-buffer-mode -1)))
(defun spacemacs//centered-buffer-mode-disable-branch () (defun spacemacs//centered-buffer-mode-disable-branch ()
"Used in `spacemacs-centered-buffer-mode'." "Used in `spacemacs-centered-buffer-mode'."
;; Don't run if the mode is disabled. ;; Don't run if the mode is disabled(we are not in the indirect buffer).
(when spacemacs--centered-buffer-mode-origin-buffer (when spacemacs--centered-buffer-mode-origin-buffer
(let* ((window (selected-window)) (let* ((window (selected-window))
(origin-buffer spacemacs--centered-buffer-mode-origin-buffer) (origin-buffer spacemacs--centered-buffer-mode-origin-buffer)
@ -223,10 +222,10 @@ minimize the performance hit when the mode isn't used."
(setq spacemacs--centered-buffer-mode-indirect-buffers nil))))))) (setq spacemacs--centered-buffer-mode-indirect-buffers nil)))))))
;; Remove hooks and advices when they are not needed anymore. ;; Remove hooks and advices when they are not needed anymore.
(unless spacemacs--centered-buffer-mode-indirect-buffers (unless spacemacs--centered-buffer-mode-indirect-buffers
(advice-remove 'spacemacs/previous-useful-buffer (advice-remove 'previous-buffer
#'spacemacs//centered-buffer-mode-prev-next-useful-buffer-advice) #'spacemacs//centered-buffer-mode-prev-next-buffer-advice)
(advice-remove 'spacemacs/next-useful-buffer (advice-remove 'next-buffer
#'spacemacs//centered-buffer-mode-prev-next-useful-buffer-advice) #'spacemacs//centered-buffer-mode-prev-next-buffer-advice)
(remove-hook 'buffer-list-update-hook (remove-hook 'buffer-list-update-hook
'spacemacs//centered-buffer-buffer-list-update-fringes) 'spacemacs//centered-buffer-buffer-list-update-fringes)
(remove-hook 'window-configuration-change-hook (remove-hook 'window-configuration-change-hook

View File

@ -63,25 +63,32 @@ keeping their content visible.
org-indent-mode org-indent-mode
view-mode view-mode
hide-line-numbers hide-line-numbers
emphasis-overlays alternative-emphasis
meta-tags-overlays alternative-tags-look
link-protocol link-protocol
org-block-line-face-remap org-block-line-face-remap
org-kbd-face-remap org-kbd-face-remap
resize-inline-images resize-inline-images)
advice-org-do-emphasis-faces)
"List of `space-doc' modificators." "List of `space-doc' modificators."
:type '(set (const center-buffer-mode) :type '(set (const center-buffer-mode)
(const org-indent-mode) (const org-indent-mode)
(const view-mode) (const view-mode)
(const hide-line-numbers) (const hide-line-numbers)
(const emphasis-overlays) (const alternative-emphasis)
(const meta-tags-overlays) (const alternative-tags-look)
(const link-protocol) (const link-protocol)
(const org-block-line-face-remap) (const org-block-line-face-remap)
(const org-kbd-face-remap) (const org-kbd-face-remap)
(const resize-inline-images) (const resize-inline-images))
(const advice-org-do-emphasis-faces)) :group 'space-doc)
(defcustom spacemacs-space-doc-center-buffer-mode-min-aspect-ratio
1.7
"Minimal `frame' aspect ration (`frame-pixel-width' divided by `frame-pixel-height')
for `spacemacs-centered-buffer-mode' to be automatically enabled.
NOTE: If `center-buffer-mode' isn't a member of `spacemacs-space-doc-modificators'
list `spacemacs-centered-buffer-mode' will not be enabled."
:type 'number
:group 'space-doc) :group 'space-doc)
(defvar spacemacs-space-doc-modificators-functions (defvar spacemacs-space-doc-modificators-functions
@ -89,13 +96,12 @@ keeping their content visible.
(org-indent-mode . spacemacs//space-doc-org-indent-mode) (org-indent-mode . spacemacs//space-doc-org-indent-mode)
(view-mode . spacemacs//space-doc-view-mode) (view-mode . spacemacs//space-doc-view-mode)
(hide-line-numbers . spacemacs//space-doc-hide-line-numbers) (hide-line-numbers . spacemacs//space-doc-hide-line-numbers)
(emphasis-overlays . spacemacs//space-doc-emphasis-overlays) (alternative-emphasis . spacemacs//space-doc-alternative-emphasis)
(meta-tags-overlays . spacemacs//space-doc-meta-tags-overlays) (alternative-tags-look . spacemacs//space-doc-alternative-tags-look)
(link-protocol . spacemacs//space-doc-link-protocol) (link-protocol . spacemacs//space-doc-link-protocol)
(org-block-line-face-remap . spacemacs//space-doc-org-block-line-face-remap) (org-block-line-face-remap . spacemacs//space-doc-org-block-line-face-remap)
(org-kbd-face-remap . spacemacs//space-doc-org-kbd-face-remap) (org-kbd-face-remap . spacemacs//space-doc-org-kbd-face-remap)
(resize-inline-images . spacemacs//space-doc-resize-inline-images) (resize-inline-images . spacemacs//space-doc-resize-inline-images))
(advice-org-do-emphasis-faces . spacemacs//space-doc-advice-org-do-emphasis-faces))
"alist of `space-doc' modificator (tag . function) for `org-mode' buffers. "alist of `space-doc' modificator (tag . function) for `org-mode' buffers.
The functions work with a current buffer and accept ENABLE(flag) argument. The functions work with a current buffer and accept ENABLE(flag) argument.
If the argument has non-nil value - enable the modifications introduced If the argument has non-nil value - enable the modifications introduced
@ -110,30 +116,34 @@ buffer to FLAG."
(spacemacs-centered-buffer-mode -1) (spacemacs-centered-buffer-mode -1)
(setq space-doc-mode old-flag)))) (setq space-doc-mode old-flag))))
(defun spacemacs//space-doc-centered-buffer-mode-hook ()
"Apply `spacemacs//space-doc-emphasis-overlays' to the
indirect buffer (because overlays aren't copied from the original one).
And calculates `spacemacs//space-doc-set-cache' (it's buffer local)."
(when space-doc-mode
(spacemacs//space-doc-set-cache t)
(when (member 'spacemacs//space-doc-emphasis-overlays
spacemacs-space-doc-modificators)
(spacemacs//space-doc-emphasis-overlays t))))
(when (member 'spacemacs//space-doc-center-buffer-mode
spacemacs-space-doc-modificators)
(add-hook 'spacemacs-centered-buffer-mode-hook
'spacemacs//space-doc-centered-buffer-mode-hook))
(defun spacemacs//space-doc-center-buffer-mode (&optional flag) (defun spacemacs//space-doc-center-buffer-mode (&optional flag)
"Enable `spacemacs-centered-buffer-mode' if flag is non nil, disable it otherwise. "Enable `spacemacs-centered-buffer-mode' if flag is non nil, disable it otherwise.
This functions is aimed to be used with `spacemacs-space-doc-modificators'." This functions is aimed to be used with `spacemacs-space-doc-modificators'."
(if (and flag (not spacemacs-centered-buffer-mode)) (when (and flag
;; `spacemacs-centered-buffer-mode' is heavy so it's better to make if deferred. (not spacemacs-centered-buffer-mode)
;; Also it has to be run when the `window-body-width' is properly calculated. (>= (/ (* (frame-pixel-width) 1.0) (frame-pixel-height))
(run-with-idle-timer 0 nil 'spacemacs-centered-buffer-mode)) spacemacs-space-doc-center-buffer-mode-min-aspect-ratio))
;; `spacemacs-centered-buffer-mode' is heavy so it's better to make if deferred.
;; Also it has to be run when the `window-body-width' is properly calculated.
(run-with-idle-timer 0 nil 'spacemacs-centered-buffer-mode))
(spacemacs-centered-buffer-mode -1)) (spacemacs-centered-buffer-mode -1))
(defun spacemacs//space-doc-centered-buffer-mode-hook ()
"Apply `spacemacs//space-doc-alternative-emphasis' to the `current-buffer'
if `space-doc-mode' is enabled."
(when space-doc-mode
(when (member 'alternative-emphasis
spacemacs-space-doc-modificators)
(spacemacs//space-doc-alternative-emphasis t))
(when (member 'alternative-tags-look
spacemacs-space-doc-modificators)
(spacemacs//space-doc-alternative-tags-look t))))
(when (member 'center-buffer-mode
spacemacs-space-doc-modificators)
(add-hook 'spacemacs-centered-buffer-mode-hook
'spacemacs//space-doc-centered-buffer-mode-hook))
(defun spacemacs//space-doc-org-indent-mode (&optional flag) (defun spacemacs//space-doc-org-indent-mode (&optional flag)
"Enable `org-indent-mode' if flag is non nil, disable it otherwise. "Enable `org-indent-mode' if flag is non nil, disable it otherwise.
This functions is aimed to be used with `spacemacs-space-doc-modificators'." This functions is aimed to be used with `spacemacs-space-doc-modificators'."
@ -194,8 +204,8 @@ appearances in the current buffer. The function uses
`match-data' set by `org-do-emphasis-faces' function." `match-data' set by `org-do-emphasis-faces' function."
;; `org-do-emphasis-faces' returns non-nil value when it ;; `org-do-emphasis-faces' returns non-nil value when it
;; found a region to emphasize. ;; found a region to emphasize.
(when (and found (when (and space-doc-mode
space-doc-mode found
(not (and (not (and
(match-string 4) (match-string 4)
(string-empty-p (string-empty-p
@ -212,8 +222,7 @@ appearances in the current buffer. The function uses
If ENABLE is non-nil, add advice `org-do-emphasis-faces' function with If ENABLE is non-nil, add advice `org-do-emphasis-faces' function with
`spacemacs//space-doc-org-do-emphasis-faces-advice'. `spacemacs//space-doc-org-do-emphasis-faces-advice'.
NOTE: `org-do-emphasis-faces' is lazy and will emphasize only part of the NOTE: `org-do-emphasis-faces' is lazy and will emphasize only part of the
current buffer so piggybacking it should be pretty performant solution. current buffer so piggybacking it should be pretty performant solution."
This functions is aimed to be used with `spacemacs-space-doc-modificators'."
(when enable (when enable
(advice-add 'org-do-emphasis-faces (advice-add 'org-do-emphasis-faces
:after :after
@ -264,13 +273,14 @@ The character should be one of the markers from `org-emphasis-alist'."
(overlay-put ending-marker-overlay (overlay-put ending-marker-overlay
'space-doc-emphasis-overlay t))) 'space-doc-emphasis-overlay t)))
(defun spacemacs//space-doc-emphasis-overlays (&optional enable) (defun spacemacs//space-doc-alternative-emphasis (&optional enable)
"Emphasis overlays. "Emphasis overlays.
If ENABLE is non-nil, overlay regions which have already been emphasized by If ENABLE is non-nil, overlay regions which have already been emphasized by
`org-do-emphasis-faces'in the current buffer. `org-do-emphasis-faces'in the current buffer.
Otherwise remove all overlays with property `space-doc-emphasis-overlay'. Otherwise remove all overlays with property `space-doc-emphasis-overlay'.
This functions is aimed to be used with `spacemacs-space-doc-modificators'." This functions is aimed to be used with `spacemacs-space-doc-modificators'."
;; Remove overlays. ;; Remove overlays.
(spacemacs//space-doc-advice-org-do-emphasis-faces enable)
(dolist (overlay (overlays-in (point-min) (point-max))) (dolist (overlay (overlays-in (point-min) (point-max)))
(when (overlay-get overlay 'space-doc-emphasis-overlay) (when (overlay-get overlay 'space-doc-emphasis-overlay)
(delete-overlay overlay))) (delete-overlay overlay)))
@ -309,7 +319,7 @@ This functions is aimed to be used with `spacemacs-space-doc-modificators'."
600))) 600)))
(org-display-inline-images))) (org-display-inline-images)))
(defun spacemacs//space-doc-meta-tags-overlays (&optional enable) (defun spacemacs//space-doc-alternative-tags-look (&optional enable)
"Modify meta tag appearance. "Modify meta tag appearance.
If ENABLE is non-nil, modify `org-mode' meta tags appearance in the current If ENABLE is non-nil, modify `org-mode' meta tags appearance in the current
buffer. buffer.