generalized outshine-sparse functions

This commit is contained in:
Thomas von Dein
2017-07-02 19:15:52 +02:00
parent 0f423fd7c6
commit 75f765f23b
2 changed files with 486 additions and 482 deletions

44
.emacs
View File

@@ -400,10 +400,14 @@
;; - Info mode: C-left+C-right history keys ;; - Info mode: C-left+C-right history keys
;; - added loader for el2markdown ;; - added loader for el2markdown
;; - removed smart-forward, it annoys me ;; - removed smart-forward, it annoys me
;; - made tvd-outshine-jump more portable, do not use hardcoded
;; regexps anymore, use outshine functions
;; ** TODO ;; ** TODO
;; - fix C-c C-j to work in non-elisp buffers too, see FIXMEs there
;; and make it recursive like a path or the like
;; - check helpful https://github.com/wilfred/helpful ;; - check helpful https://github.com/wilfred/helpful
;; - check no-littering https://github.com/tarsius/no-littering ;; - check no-littering https://github.com/tarsius/no-littering
;; - submit novel + mark-copy-yank-things-mode to MELPA ;; - submit novel + mark-copy-yank-things-mode to MELPA
@@ -1968,9 +1972,8 @@ col1, col2"
;; for config-general-mode (which inherits from conf-mode). ;; for config-general-mode (which inherits from conf-mode).
(add-hook 'config-general-mode-hook 'electric-indent-mode) (add-hook 'config-general-mode-hook 'electric-indent-mode)
;; empty for now ;; enable outshine
(add-hook 'config-general-mode-hook '(lambda () (add-hook 'config-general-mode-hook 'outline-minor-mode)
t))
;; -------------------------------------------------------------------------------- ;; --------------------------------------------------------------------------------
;; ** Text Manupilation ;; ** Text Manupilation
@@ -2722,7 +2725,6 @@ down and unfold it, otherwise jump paragraph as usual."
org-fontify-done-headline t org-fontify-done-headline t
org-pretty-entities t org-pretty-entities t
org-confirm-babel-evaluate nil) org-confirm-babel-evaluate nil)
; shortcuts ; shortcuts
(setq org-speed-commands-user (setq org-speed-commands-user
(quote ( (quote (
@@ -2738,7 +2740,6 @@ down and unfold it, otherwise jump paragraph as usual."
("z" . org-refile) ; archive the (sub-)tree ("z" . org-refile) ; archive the (sub-)tree
("a" . org-attach) ; manage attachments ("a" . org-attach) ; manage attachments
))) )))
; same as toggle ; same as toggle
(local-set-key (kbd "C-t") 'org-todo) (local-set-key (kbd "C-t") 'org-todo)
@@ -3127,22 +3128,21 @@ specify another regex for cell splitting."
(add-hook 'emacs-lisp-mode-hook '(lambda () (add-hook 'emacs-lisp-mode-hook '(lambda ()
(outline-minor-mode))) (outline-minor-mode)))
;; I do have my own outshine parser here. It generates an alist of all ;; Generate an alist of all headings with each position in buffer and
;; headings with each position in buffer. ;; use this later to jump to those positions with IDO.
(make-variable-buffer-local 'tvd-headings) (make-variable-buffer-local 'tvd-headings)
(defun tvd-outshine-is-heading-p (&optional line)
"return t if current line or LINE is a heading"
(tvd-starts-with (or line (tvd-get-line)) ";; *"))
(defun tvd-outshine-get-level (heading) (defun tvd-outshine-get-level (heading)
"return level of HEADING as number, or nil" "Return level of HEADING as number, or nil"
(if (string-match ";; \\(*+\\)" heading) (if (string-match " \\(*+\\) " heading) ; normal outline heading
(length (match-string 1 heading)))) (length (match-string 1 heading))
(when (string-match "^;;\\(;+\\) " heading) ; else look for elisp heading
(length (match-string 1 heading)))))
(defun tvd-outshine-cl-heading (heading) (defun tvd-outshine-cl-heading (heading)
"clean HEADING" (let ((regex (cadar outshine-imenu-preliminary-generic-expression)))
(replace-regexp-in-string ";; \\*+ " "" heading)) (when (string-match regex heading)
(match-string-no-properties 1 heading))))
(defun tvd-outshine-parse-headings () (defun tvd-outshine-parse-headings ()
"extract outshine headings of current buffer" "extract outshine headings of current buffer"
@@ -3153,7 +3153,7 @@ specify another regex for cell splitting."
(beginning-of-buffer) (beginning-of-buffer)
(while (not (eobp)) (while (not (eobp))
(setq line (tvd-get-line)) (setq line (tvd-get-line))
(when (tvd-outshine-is-heading-p line) (when (outline-on-heading-p t)
(add-to-list 'tvd-headings (cons (tvd-outshine-cl-heading line) (point)))) (add-to-list 'tvd-headings (cons (tvd-outshine-cl-heading line) (point))))
(forward-line))))) (forward-line)))))
@@ -3169,15 +3169,12 @@ specify another regex for cell splitting."
(setq l (tvd-outshine-get-level (tvd-get-line))) (setq l (tvd-outshine-get-level (tvd-get-line)))
(add-to-list 'tree (list (point) l)) (add-to-list 'tree (list (point) l))
(when (eq l 1) (when (eq l 1)
(setq done t)) (setq done t)))
)
(outline-hide-other) (outline-hide-other)
(dolist (pos tree) (dolist (pos tree)
(goto-char (car pos)) (goto-char (car pos))
(outline-cycle)))) (outline-cycle))))
;; Using the functions above I now can just hit C-c C-j and IDO to
;; some heading, which is damn fast and great.
(defun tvd-outshine-jump () (defun tvd-outshine-jump ()
"jump to an outshine heading with IDO prompt, "jump to an outshine heading with IDO prompt,
update heading list if neccessary." update heading list if neccessary."
@@ -3210,6 +3207,11 @@ update heading list if neccessary."
("q" . widen) ("q" . widen)
))))))) )))))))
;; Narrowing now works within the headline rather than requiring to be on it
(advice-add 'outshine-narrow-to-subtree :before
(lambda (&rest args) (unless (outline-on-heading-p t)
(outline-previous-visible-heading 1))))
;; convert outshine buffer to org buffer using outorg, which is part ;; convert outshine buffer to org buffer using outorg, which is part
;; of outshine. ;; of outshine.
(defun outshine-to-org () (defun outshine-to-org ()

File diff suppressed because it is too large Load Diff