Skip to content

Commit

Permalink
Refactored GH style anchor search.
Browse files Browse the repository at this point in the history
  • Loading branch information
JAremko committed Mar 23, 2016
1 parent e9f9a53 commit b9d0869
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions core/core-funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,37 +172,27 @@ Supported properties:
(org-indent-mode)
(view-mode)

(goto-char (point-min))

;; Enable `space-doc-mode' if defined.
(when (and (boundp 'space-doc-mode)
(fboundp 'space-doc-mode))
(space-doc-mode))

(goto-char (point-min))

(when anchor-text
(if (string= anchor-text "^")

(re-search-forward anchor-text)

(progn (save-excursion
(let
;; Copied from "toc-org" to avoid requiring the package.
((toc-regexp (concat "^*.*:toc\\([@_][0-9]\\|"
"\\([@_][0-9][@_][a-zA-Z]+\\)"
"\\)?:\\($\\|[^ ]*:$\\)")))
(when (re-search-forward toc-regexp nil t)
;; Expand TOC.
(outline-show-subtree))))

(when (re-search-forward anchor-text nil t)
(let ((cur-line (buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))
(toc-org-rel-link "\\[\\[\\#[[:alnum:]_-]+\\]\\[.*\\]\\]"))
;; If the `point' is over a TOC-org relative heading link -
;; go to the heading.
(when (string-match-p toc-org-rel-link cur-line)
(org-open-at-point)))))))
;; If `anchor-text' is GitHub style link.
(if (string-prefix-p "#" anchor-text)
;; If the toc-org package is loaded.
(if (require 'toc-org nil 'noerror)
;; 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 "Can't follow the GitHub style URL: '%s' without the org layer." anchor-text)))

(re-search-forward anchor-text)))

(beginning-of-line)

Expand Down

0 comments on commit b9d0869

Please sign in to comment.