Improve docs

Bug fix
Reorganize code
This commit is contained in:
JAremko 2016-04-25 07:14:03 +03:00 committed by syl20bnr
parent 0b9add2f0d
commit 31d2a149d5

View file

@ -51,6 +51,7 @@ keeping their content visible.
spacemacs//space-doc-modf-link-protocol spacemacs//space-doc-modf-link-protocol
spacemacs//space-doc-modf-org-block-line-face-remap spacemacs//space-doc-modf-org-block-line-face-remap
spacemacs//space-doc-modf-org-kbd-face-remap spacemacs//space-doc-modf-org-kbd-face-remap
spacemacs//space-doc-modf-advice-org-do-emphasis-faces
(lambda (flag) (spacemacs//space-doc-run-modfs-deferred (lambda (flag) (spacemacs//space-doc-run-modfs-deferred
'() '()
flag ))) flag )))
@ -70,7 +71,7 @@ It is set by `spacemacs//space-doc-set-space-doc-cache'.")
(defun spacemacs//space-doc-set-space-doc-cache (&optional flag) (defun spacemacs//space-doc-set-space-doc-cache (&optional flag)
"Set `spacemacs--space-doc-cache' to filled "Set `spacemacs--space-doc-cache' to filled
`spacemacs//space-doc-cache' structure. FLAG is ignored." `spacemacs//space-doc-cache' structure."
(setq spacemacs--space-doc-cache (setq spacemacs--space-doc-cache
(if flag (if flag
@ -100,22 +101,26 @@ It is set by `spacemacs//space-doc-set-space-doc-cache'.")
(defun spacemacs//space-doc-org-do-emphasis-faces-advice (found) (defun spacemacs//space-doc-org-do-emphasis-faces-advice (found)
"If FOUND has non-nil value - modify emphasized regions "If FOUND has non-nil value - modify emphasized regions
appearances in the current buffer. The function uses 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."
NOTE: `org-do-emphasis-faces' is lazy and will emphasize only
part of the buffer. So piggybacking it should be pretty
performant solution."
;; `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 spacemacs--space-doc-cache) (when (and found space-doc-mode)
(spacemacs//space-doc-emphasis-region (spacemacs//space-doc-emphasis-region
(match-beginning 2) (match-beginning 2)
(match-end 2))) (match-end 2)))
found) found)
(defun spacemacs//space-doc-modf-advice-org-do-emphasis-faces (&optional enable)
"If ENABLE has non-nil value - advice `org-do-emphasis-faces' function
with `spacemacs//space-doc-org-do-emphasis-faces-advice'.
NOTE: `org-do-emphasis-faces' is lazy and will emphasize only part of the
current buffer so piggybacking it should be pretty performant solution."
(when enable
(advice-add 'org-do-emphasis-faces (advice-add 'org-do-emphasis-faces
:after :after
'spacemacs//space-doc-org-do-emphasis-faces-advice) #'spacemacs//space-doc-org-do-emphasis-faces-advice)))
(defun spacemacs//space-doc-emphasis-region (begin end) (defun spacemacs//space-doc-emphasis-region (begin end)
"Emphasis region based on its leading character. "Emphasis region based on its leading character.
@ -170,22 +175,23 @@ from `org-emphasis-alist'."
'space-doc-emphasis-overlay t))) 'space-doc-emphasis-overlay t)))
(defun spacemacs//space-doc-modf-emphasis-overlays (&optional enable) (defun spacemacs//space-doc-modf-emphasis-overlays (&optional enable)
"If ENABLE has non-nil value - overlay regions which have already been "If ENABLE has non-nil value - overlay regions which have
emphasized by `org-do-emphasis-faces'. Otherwise remove all overlays already been emphasized by `org-do-emphasis-faces'
from the current buffer with property `space-doc-emphasis-overlay'." in the current buffer. Otherwise remove all overlays
with property `space-doc-emphasis-overlay'."
(if enable ;; Remove overlays.
(dolist (overlay (overlays-in (point-min) (point-max)))
(when (overlay-get overlay 'space-doc-emphasis-overlay)
(delete-overlay overlay)))
(when enable
(dolist (emphasized-region (dolist (emphasized-region
(spacemacs//space-doc-find-regions-by-text-property (spacemacs//space-doc-find-regions-by-text-property
'org-emphasis t)) 'org-emphasis t))
(spacemacs//space-doc-emphasis-region (spacemacs//space-doc-emphasis-region
(car emphasized-region) (car emphasized-region)
(cadr emphasized-region))) (cadr emphasized-region)))))
;; Remove overlays.
(dolist (overlay (overlays-in (point-min) (point-max)))
(when (overlay-get overlay 'space-doc-emphasis-overlay)
(delete-overlay overlay)))))
(defun spacemacs//space-doc-modf-org-kbd-face-remap (&optional enable) (defun spacemacs//space-doc-modf-org-kbd-face-remap (&optional enable)
"If ENABLE has non-nil value - removes boxes from the `org-kbd' "If ENABLE has non-nil value - removes boxes from the `org-kbd'
@ -201,9 +207,10 @@ default."
(defun spacemacs//space-doc-modf-meta-tags-overlays (&optional enable) (defun spacemacs//space-doc-modf-meta-tags-overlays (&optional enable)
"If ENABLE has non-nil value - modify `org-mode' meta tags "If ENABLE has non-nil value - modify `org-mode' meta tags
appearance in the current `org-mode' buffer. Otherwise - disable." appearance in the current buffer. Otherwise - disable."
(if enable (if enable
;; TODO add more types of tags or meta-line if needed.
(let* ((invisible-org-meta-tags-list (let* ((invisible-org-meta-tags-list
`(;; Hide TITLE tag. `(;; Hide TITLE tag.
("\\([ \t]*\\#\\+TITLE\\:\[ \t]*\\)" ("\\([ \t]*\\#\\+TITLE\\:\[ \t]*\\)"
@ -252,9 +259,9 @@ appearance in the current `org-mode' buffer. Otherwise - disable."
(delete-overlay overlay))))) (delete-overlay overlay)))))
(defun spacemacs//space-doc-modf-org-block-line-face-remap (&optional enable) (defun spacemacs//space-doc-modf-org-block-line-face-remap (&optional enable)
"If ENABLE has non-nil value - hide text in the code block meta lines "If ENABLE has non-nil value - hide text of the code block meta lines
in the current buffer. If the blocks have background color text won't be in the current buffer. If the blocks have background color text won't be
removed because it makes them look ugly with some themes. masked because it makes them look ugly with some themes.
If ENABLE has nil value - revert to the default." If ENABLE has nil value - revert to the default."
(if enable (if enable
@ -332,7 +339,8 @@ FLAG is passed through."
(property value &optional start end) (property value &optional start end)
"Return a list of pairs (region-beginning region-end) in "Return a list of pairs (region-beginning region-end) in
the current buffer. If START or END has non-nil value - use them as the current buffer. If START or END has non-nil value - use them as
boundaries. NOTE: Specified region should be fontified." boundaries.
NOTE: It can find only fontified regions."
(let ((p-min (or start (point-min))) (let ((p-min (or start (point-min)))
(p-max (or end (point-max))) (p-max (or end (point-max)))