Update docstring for space-doc and delete some empty lines

This commit is contained in:
syl20bnr 2016-06-26 13:47:52 -04:00
parent 38814881dc
commit 4ad27cfea8

View file

@ -47,7 +47,7 @@ keeping their content visible.
(defvar spacemacs--space-doc-modificators (defvar spacemacs--space-doc-modificators
'(spacemacs//space-doc-org-indent-mode '(spacemacs//space-doc-org-indent-mode
spacemacs//space-doc-view-mode spacemacs//space-doc-view-mode
spacemacs//space-doc-set-space-doc-cache spacemacs//space-doc-set-cache
spacemacs//space-doc-hide-line-numbers spacemacs//space-doc-hide-line-numbers
spacemacs//space-doc-modf-emphasis-overlays spacemacs//space-doc-modf-emphasis-overlays
spacemacs//space-doc-modf-meta-tags-overlays spacemacs//space-doc-modf-meta-tags-overlays
@ -65,24 +65,27 @@ If the argument has non-nil value - enable the modifications introduced
by the function. Otherwise - disable.") by the function. Otherwise - disable.")
(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.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(org-indent-mode (if flag 1 -1))) (org-indent-mode (if flag 1 -1)))
(defun spacemacs//space-doc-view-mode (&optional flag) (defun spacemacs//space-doc-view-mode (&optional flag)
"Enable `view-mode' if flag is non nil, disable it otherwise.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(view-mode (if flag 1 -1))) (view-mode (if flag 1 -1)))
(cl-defstruct spacemacs//space-doc-cache (cl-defstruct spacemacs-space-doc-cache-struct
marker-face marker-face
btn-marker-face btn-marker-face
kbd-marker) kbd-marker)
(defvar-local spacemacs--space-doc-cache nil (defvar-local spacemacs--space-doc-cache nil
"Global variable of struct `spacemacs//space-doc-cache'. "Global variable of struct `spacemacs-space-doc-cache-struct'.
It is set by `spacemacs//space-doc-set-space-doc-cache'.") It is set by `spacemacs//space-doc-set-cache'.")
(defun spacemacs//space-doc-set-space-doc-cache (&optional flag)
"Set `spacemacs--space-doc-cache' to filled
`spacemacs//space-doc-cache' structure."
(defun spacemacs//space-doc-set-cache (&optional flag)
"Set `spacemacs--space-doc-cache'.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(setq spacemacs--space-doc-cache (setq spacemacs--space-doc-cache
(if flag (if flag
(let* ((kbd-bg (or (face-background 'org-kbd) (let* ((kbd-bg (or (face-background 'org-kbd)
@ -103,13 +106,14 @@ It is set by `spacemacs//space-doc-set-space-doc-cache'.")
(when (member 'org-kbd el) (when (member 'org-kbd el)
(return (car el)))))) (return (car el))))))
(make-spacemacs//space-doc-cache (make-spacemacs-space-doc-cache-struct
:marker-face marker-face :marker-face marker-face
:btn-marker-face btn-marker-face :btn-marker-face btn-marker-face
:kbd-marker kbd-marker))))) :kbd-marker kbd-marker)))))
(defun spacemacs//space-doc-hide-line-numbers (&optional enable) (defun spacemacs//space-doc-hide-line-numbers (&optional enable)
"If ENABLE is non-nil then toggle off the line numbers." "If ENABLE is non-nil then toggle off the line numbers.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(if enable (if enable
(spacemacs/toggle-line-numbers-off) (spacemacs/toggle-line-numbers-off)
(when dotspacemacs-line-numbers (when dotspacemacs-line-numbers
@ -119,7 +123,6 @@ It is set by `spacemacs//space-doc-set-space-doc-cache'.")
"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."
;; `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 found
@ -134,11 +137,12 @@ appearances in the current buffer. The function uses
found) found)
(defun spacemacs//space-doc-modf-advice-org-do-emphasis-faces (&optional enable) (defun spacemacs//space-doc-modf-advice-org-do-emphasis-faces (&optional enable)
"If ENABLE has non-nil value - advice `org-do-emphasis-faces' function "Advise org-do-emphasis-faces.
with `spacemacs//space-doc-org-do-emphasis-faces-advice'. If ENABLE is non-nil, add 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 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
@ -146,17 +150,13 @@ current buffer so piggybacking it should be pretty performant solution."
(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.
The character should be one of the markers The character should be one of the markers from `org-emphasis-alist'."
from `org-emphasis-alist'."
(let* ((beginning-marker-overlay nil) (let* ((beginning-marker-overlay nil)
(ending-marker-overlay nil)) (ending-marker-overlay nil))
(setq beginning-marker-overlay (setq beginning-marker-overlay
(make-overlay begin (1+ begin)) (make-overlay begin (1+ begin))
ending-marker-overlay ending-marker-overlay
(make-overlay (1- end) end)) (make-overlay (1- end) end))
(if (string= (buffer-substring-no-properties begin (if (string= (buffer-substring-no-properties begin
(1+ begin)) (1+ begin))
(spacemacs//space-doc-cache-kbd-marker (spacemacs//space-doc-cache-kbd-marker
@ -170,7 +170,6 @@ from `org-emphasis-alist'."
'face 'face
(spacemacs//space-doc-cache-btn-marker-face (spacemacs//space-doc-cache-btn-marker-face
spacemacs--space-doc-cache))) spacemacs--space-doc-cache)))
;; If inside table. ;; If inside table.
(if (save-excursion (if (save-excursion
(goto-char begin) (goto-char begin)
@ -185,28 +184,25 @@ from `org-emphasis-alist'."
'face 'face
(spacemacs//space-doc-cache-marker-face (spacemacs//space-doc-cache-marker-face
spacemacs--space-doc-cache))) spacemacs--space-doc-cache)))
(overlay-put beginning-marker-overlay (overlay-put beginning-marker-overlay
'invisible t) 'invisible t)
(overlay-put ending-marker-overlay (overlay-put ending-marker-overlay
'invisible t))) 'invisible t)))
(overlay-put beginning-marker-overlay (overlay-put beginning-marker-overlay
'space-doc-emphasis-overlay t) 'space-doc-emphasis-overlay t)
(overlay-put ending-marker-overlay (overlay-put ending-marker-overlay
'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 "Emphasis overlays.
already been emphasized by `org-do-emphasis-faces' If ENABLE is non-nil, overlay regions which have already been emphasized by
in the current buffer. Otherwise remove all overlays `org-do-emphasis-faces'in the current buffer.
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'."
;; Remove overlays. ;; Remove overlays.
(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)))
(when enable (when enable
(dolist (emphasized-region (dolist (emphasized-region
(spacemacs//space-doc-find-regions-by-text-property (spacemacs//space-doc-find-regions-by-text-property
@ -216,9 +212,11 @@ with property `space-doc-emphasis-overlay'."
(cadr emphasized-region))))) (cadr emphasized-region)))))
(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' "Remove boxes for key bindings.
face in the current `org-mode' buffer. Otherwise - reverts them to If ENABLE is non-nil, removes boxes from the `org-kbd'face in the current
default." `org-mode' buffer.
Otherwise, reverts them to default.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(if enable (if enable
(set (make-local-variable (set (make-local-variable
'spacemacs--space-doc-org-kbd-face-remap-cookie) 'spacemacs--space-doc-org-kbd-face-remap-cookie)
@ -228,7 +226,9 @@ default."
spacemacs--space-doc-org-kbd-face-remap-cookie))) spacemacs--space-doc-org-kbd-face-remap-cookie)))
(defun spacemacs//space-doc-modf-resize-inline-images (&optional enable) (defun spacemacs//space-doc-modf-resize-inline-images (&optional enable)
"If ENABLE is non nil then resize inline images." "Resize inline images.
If ENABLE is non nil then resize inline images.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
;; resizing is always performed even when the image is smaller ;; resizing is always performed even when the image is smaller
;; so we don't resize in README.org buffers for now ;; so we don't resize in README.org buffers for now
(let ((org-image-actual-width (let ((org-image-actual-width
@ -238,9 +238,11 @@ default."
(org-display-inline-images))) (org-display-inline-images)))
(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 "Modify meta tag appearance.
appearance in the current buffer. Otherwise - disable." If ENABLE is non-nil, modify `org-mode' meta tags appearance in the current
buffer.
Otherwise, disable modifcations.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(if enable (if enable
;; TODO add more types of tags or meta-line if needed. ;; TODO add more types of tags or meta-line if needed.
(let* ((invisible-org-meta-tags-list (let* ((invisible-org-meta-tags-list
@ -269,11 +271,9 @@ appearance in the current buffer. Otherwise - disable."
,(unless (face-background 'org-block-end-line) ,(unless (face-background 'org-block-end-line)
'("^[ \t]*\\#\\+end_src.*\n\\(\n\\)[^\\*]" '("^[ \t]*\\#\\+end_src.*\n\\(\n\\)[^\\*]"
invisible t))))) invisible t)))))
;; Remove nils. ;; Remove nils.
(setq invisible-org-meta-tags-list (setq invisible-org-meta-tags-list
(remove nil invisible-org-meta-tags-list)) (remove nil invisible-org-meta-tags-list))
;; Make `org-mode' meta tags invisible. ;; Make `org-mode' meta tags invisible.
(dolist (tag invisible-org-meta-tags-list) (dolist (tag invisible-org-meta-tags-list)
(save-excursion (save-excursion
@ -284,18 +284,18 @@ appearance in the current buffer. Otherwise - disable."
(match-end 1)))) (match-end 1))))
(overlay-put new-overlay (cadr tag) (cddr tag)) (overlay-put new-overlay (cadr tag) (cddr tag))
(overlay-put new-overlay 'space-doc-tag-overlay t)))))) (overlay-put new-overlay 'space-doc-tag-overlay t))))))
;; Remove overlays. ;; Remove overlays.
(dolist (overlay (overlays-in (point-min) (point-max))) (dolist (overlay (overlays-in (point-min) (point-max)))
(when (overlay-get overlay 'space-doc-tag-overlay) (when (overlay-get overlay 'space-doc-tag-overlay)
(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 of the code block meta lines "Hide drawers.
in the current buffer. If the blocks have background color text won't be If ENABLE is non-nil, hide text of the code block meta lines in the current
masked because it makes them look ugly with some themes. buffer. If the blocks have background color text won't be masked because it
If ENABLE has nil value - revert to the default." makes them look ugly with some themes.
If ENABLE has nil, revert to the default.
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(if enable (if enable
(let* ((default-bg (or (face-background 'default) (let* ((default-bg (or (face-background 'default)
'unspecified)) 'unspecified))
@ -329,9 +329,11 @@ If ENABLE has nil value - revert to the default."
spacemacs--space-doc-org-block-end-line-face-remap-cookie)))) spacemacs--space-doc-org-block-end-line-face-remap-cookie))))
(defun spacemacs//space-doc-modf-link-protocol (&optional enable) (defun spacemacs//space-doc-modf-link-protocol (&optional enable)
"If ENABLE has non-nil value - use `spacemacs//space-doc-open' to "Open HTTPS links in the curren buffer.
open 'https' links in the current `org-mode' buffer. Otherwise open If ENABLE is non-nil, use `spacemacs//space-doc-open' to open HTTPS links
them in the browser(default behavior)." in the current `org-mode' buffer.
Otherwise open them in the browser(default behavior).
This functions is aimed to be used with `spacemacs--space-doc-modificators'."
(if enable (if enable
(progn (progn
;; Make `space-doc' https link opener buffer local ;; Make `space-doc' https link opener buffer local
@ -339,7 +341,6 @@ them in the browser(default behavior)."
(make-local-variable 'org-link-types) (make-local-variable 'org-link-types)
(make-local-variable 'org-link-protocols) (make-local-variable 'org-link-protocols)
(org-add-link-type "https" 'spacemacs//space-doc-open)) (org-add-link-type "https" 'spacemacs//space-doc-open))
(kill-local-variable 'org-link-types) (kill-local-variable 'org-link-types)
(kill-local-variable 'org-link-protocols)) (kill-local-variable 'org-link-protocols))
;; Trigger `org-mode' internal updates. ;; Trigger `org-mode' internal updates.
@ -347,9 +348,10 @@ them in the browser(default behavior)."
(org-add-link-type nil)) (org-add-link-type nil))
(defun spacemacs//space-doc-open (path) (defun spacemacs//space-doc-open (path)
"If PATH argument is a link to an .org file that is located "Open PATH link.
in the Spacemacs GitHub repository - Visit the local copy If PATH argument is a link to an .org file that is located in the Spacemacs
of the file with `spacemacs/view-org-file'. GitHub repository then visit the local copy of the file with
`spacemacs/view-org-file'.
Open all other links with `browse-url'." Open all other links with `browse-url'."
(let ((git-url-root-regexp (let ((git-url-root-regexp
(concat "\\/\\/github\\.com\\/syl20bnr\\/spacemacs\\/blob" (concat "\\/\\/github\\.com\\/syl20bnr\\/spacemacs\\/blob"