Add org-mode link-type "https" to open local copies
The https link-type opens the local copies of the Spacemacs documentation files with the spacemacs/view-org-file function. It supports GitHub style heading links For example, the link: https://github.com/syl20bnr/spacemacs/blob/develop/layers/org/README.org#links Will be handled similary to as if it was: file:~/.emacs.d/layers/org/README.org::*links Also the `space-doc' mode will be applied. Refactored GH style anchor search.
This commit is contained in:
parent
30f971d89c
commit
8c3d05ee47
|
@ -168,11 +168,25 @@ Supported properties:
|
|||
(find-file file)
|
||||
(org-indent-mode)
|
||||
(view-mode)
|
||||
;; Enable `space-doc-mode' if defined.
|
||||
(when (bound-and-true-p space-doc-mode)
|
||||
(space-doc-mode))
|
||||
(goto-char (point-min))
|
||||
(when anchor-text
|
||||
(re-search-forward anchor-text))
|
||||
;; If `anchor-text' is GitHub style link.
|
||||
(if (string-prefix-p "#" anchor-text)
|
||||
;; If the toc-org package is loaded.
|
||||
(if (configuration-layer/package-usedp 'toc-org)
|
||||
;; For each heading. Search the heading that corresponds
|
||||
;; to `anchor-text'.
|
||||
(while (and (re-search-forward "^[\\*]+\s\\(.*\\).*$" nil t)
|
||||
(not (string= (toc-org-hrefify-gh (match-string 1))
|
||||
anchor-text))))
|
||||
;; This is not a problem because without the space-doc package
|
||||
;; those links will be opened in the browser.
|
||||
(message (format (concat "Can't follow the GitHub style anchor: '%s' "
|
||||
"without the org layer.") anchor-text)))
|
||||
(re-search-forward anchor-text)))
|
||||
(beginning-of-line)
|
||||
(cond
|
||||
((eq expand-scope 'subtree)
|
||||
|
|
|
@ -7,6 +7,22 @@
|
|||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;; Description:
|
||||
;; This package provides:
|
||||
;; - `space-doc-mode' - buffer local minor mode
|
||||
;; for viewing the Spacemacs documentation files.
|
||||
;; The mode hides org meta tags to improve readability.
|
||||
;; - `org-mode' link-type "https" that opens the local
|
||||
;; copies of the Spacemacs documentation files with
|
||||
;; `spacemacs/view-org-file' and supports GitHub style
|
||||
;; heading links.
|
||||
;;
|
||||
;; For example, the link:
|
||||
;; https://github.com/syl20bnr/spacemacs/blob/develop/layers/org/README.org#links
|
||||
;; Will be handled similary to as if it was:
|
||||
;; file:~/.emacs.d/layers/org/README.org::*links
|
||||
;; Also the `space-doc' mode will be applied.
|
||||
|
||||
;;; License: GPLv3
|
||||
;;; Code:
|
||||
(require 'face-remap)
|
||||
|
@ -55,5 +71,23 @@ keeping their content visible."
|
|||
(buffer-name)))
|
||||
(setq org-mode nil))))
|
||||
|
||||
(defun spacemacs//space-doc-open (path)
|
||||
"If the `path' argument is a link to an .org file that is located
|
||||
in the Spacemacs GitHub repository - Visit the local copy
|
||||
of the file with `spacemacs/view-org-file'.
|
||||
Open all other links with `browse-url'."
|
||||
(let ((git-url-root-regexp
|
||||
(concat "\\/\\/github\\.com\\/syl20bnr"
|
||||
"\\/spacemacs\\/blob\\/[^/]+\\/\\(.*\\.org\\)\\(\\#.*\\)?")))
|
||||
(if (string-match git-url-root-regexp path)
|
||||
(spacemacs/view-org-file (concat user-emacs-directory
|
||||
(match-string 1 path))
|
||||
(or (match-string 2 path)
|
||||
"^")
|
||||
'subtree)
|
||||
(browse-url (concat "https://" path)))))
|
||||
|
||||
(org-add-link-type "https" 'spacemacs//space-doc-open)
|
||||
|
||||
(provide 'space-doc)
|
||||
;;; space-doc.el ends here
|
||||
|
|
Loading…
Reference in a new issue