Skip to content

Commit

Permalink
Unified outline op & fatal fix
Browse files Browse the repository at this point in the history
  • Loading branch information
c0001 committed Jul 22, 2024
1 parent ffd392d commit f99052a
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 33 deletions.
35 changes: 35 additions & 0 deletions elements/core/tentacles/entropy-emacs-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,41 @@ enabled at current org buffer. "
;; then inject the defautly one
(add-to-list 'org-file-apps '(directory . emacs)))

;; ***** eemacs outline unified specification

(defun eemacs//outline-on-org-mode-p nil
(derived-mode-p 'org-mode))

(entropy/emacs-outline-op-regist-op
'org-mode 'at-heading-p
'eemacs//outline-on-org-mode-p
(lambda (&rest _) (org-at-heading-p)))

(entropy/emacs-outline-op-regist-op
'org-mode 'get-current-head-level
'eemacs//outline-on-org-mode-p
(lambda (&rest _) (org-current-level)))

(entropy/emacs-outline-op-regist-op
'org-mode 'goto-prev-head
'eemacs//outline-on-org-mode-p
(lambda (&rest _)
(outline-previous-heading) (forward-line 0)
(and (org-at-heading-p) t)))

(entropy/emacs-outline-op-regist-op
'org-mode 'goto-next-head
'eemacs//outline-on-org-mode-p
(lambda (&rest _)
(outline-next-heading) (forward-line 0)
(and (org-at-heading-p) t)))

(entropy/emacs-outline-op-regist-op
'org-mode 'map-region
'eemacs//outline-on-org-mode-p
(lambda (&rest args)
(apply 'org-map-region args)))

;; **** ___end___
)

Expand Down
93 changes: 61 additions & 32 deletions elements/core/tentacles/entropy-emacs-structure.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
;; ** require
(use-package outline
:ensure nil
;; *** preface
:preface
(defvar outline-regexp)

;; *** eemacs unified outline interface

(defun entropy/outline-previous-visible-heading (&optional arg)
"Like `outline-previous-visible-heading' but goto to parent
heading as `entropy/emacs-org-previous-visible-heading' when
Expand All @@ -49,13 +52,16 @@ prefix arg was `(4)' i.e. the single `C-u' type."
(outline-previous-visible-heading
(prefix-numeric-value arg)))))

;; *** init
:init
;; make `outline-minor-mode' enabled in markdown mode since its
;; based on thus so that we can invoke some eemacs outline specs for
;; markdown as well.
(add-hook 'markdown-mode-hook #'outline-minor-mode)

;; *** config
:config
;; **** keybinding
(define-key outline-mode-map
(kbd "C-c C-p")
#'entropy/outline-previous-visible-heading)
Expand All @@ -79,7 +85,10 @@ prefix arg was `(4)' i.e. the single `C-u' type."
'outline-move-subtree-up)
(define-key outline-mode-map
(kbd entropy/emacs-ukrd-outline-move-subtree-down)
'outline-move-subtree-down))
'outline-move-subtree-down)

;; *** __config_end__
)

;; ** libraries
;; function for universal code folding
Expand Down Expand Up @@ -1225,6 +1234,36 @@ This function is an around advice for `outshine-mode'."
:around
#'entropy/emacs-structure--outshine-mode-around-adv)

;; **** eemacs outline unified

(defun eemacs//outline-on-outshine-mode-p nil
(bound-and-true-p outshine-mode))

(entropy/emacs-outline-op-regist-op
'outshine-mode 'at-heading-p
'eemacs//outline-on-outshine-mode-p
(lambda (&rest _) (looking-at-p outline-regexp)))

(entropy/emacs-outline-op-regist-op
'outshine-mode 'get-current-head-level
'eemacs//outline-on-outshine-mode-p
(lambda (&rest _) (outshine-calc-outline-level)))

(entropy/emacs-outline-op-regist-op
'outshine-mode 'goto-prev-head
'eemacs//outline-on-outshine-mode-p
(lambda (&rest _)
(outline-previous-heading) (forward-line 0)
(and (looking-at-p outline-regexp) t)))

(entropy/emacs-outline-op-regist-op
'outshine-mode 'goto-next-head
'eemacs//outline-on-outshine-mode-p
(lambda (&rest _)
(outline-next-heading) (forward-line 0)
(and (looking-at-p outline-regexp) t)))

;; *** __end__
)

;; ** benefit interactively functions
Expand Down Expand Up @@ -1258,7 +1297,6 @@ amounts."
calc-depth-1?))
(temp-buffer (get-buffer-create "*eemacs/org-subtree-counts-check*"))
(cur-mode major-mode)
(outline-raw-p (derived-mode-p 'outline-mode))
(cur-prefix
(if (and (listp cur-prefix) (not (null cur-prefix)))
(floor (log (car cur-prefix) 4))
Expand All @@ -1273,36 +1311,26 @@ amounts."
(outline-up-heading cur-prefix)
(point)))
(t (point-min))))
(ot-gcl-func (entropy/emacs-outline-op-get-op 'get-current-head-level))
;; (ot-gnl-func (entropy/emacs-outline-op-get-op 'get-next-head-level))
(ot-gph-func (entropy/emacs-outline-op-get-op 'goto-prev-head))
(ot-gnh-func (entropy/emacs-outline-op-get-op 'goto-next-head))
(ot-mapreg-func (entropy/emacs-outline-op-get-op 'map-region))
(see-level
(lambda (&optional no-jump)
(save-excursion
(if outline-raw-p
(if (eq major-mode 'org-mode)
(let ((org-level (save-mark-and-excursion
(org-outline-level))))
(if org-level
(cond
((= 0 org-level)
(user-error "no backward org heading found"))
(t
org-level))
(user-error "no org heading found")))
(progn
(unless no-jump
(outline-back-to-heading))
(outline-level)))
(progn
(entropy/emacs-require-only-once 'outshine)
(unless (bound-and-true-p outshine-mode)
(outshine-mode 1))
(or (outshine-calc-outline-level)
(user-error "no org heading found")))))))
(cur-level
(or
(condition-case nil
(funcall see-level)
(t 0))
0))
(lambda (&optional no-jump noerr)
(let (cl)
(or
(save-excursion
(if (setq cl (funcall ot-gcl-func)) cl
(if no-jump nil
(if (funcall ot-gph-func) (funcall ot-gcl-func)
(goto-char (point-min))
(when (funcall ot-gnh-func)
(setq cl (funcall ot-gcl-func))
(cl-decf cl))))))
(unless noerr
(error "see-level: null obtained"))))))
(cur-level (or (funcall see-level nil t) 0))
(end-pos
(condition-case nil
(progn
Expand All @@ -1318,7 +1346,8 @@ amounts."
(insert subtree-content)
(funcall cur-mode)
(goto-char (point-min))
(outline-map-region
(funcall
ot-mapreg-func
(if calc-depth-1?
(lambda (&rest _)
(let* ((pos-level (funcall see-level 'no-jump)))
Expand Down
43 changes: 43 additions & 0 deletions elements/core/wasteland/func-binds/entropy-emacs-defun.el
Original file line number Diff line number Diff line change
Expand Up @@ -12005,6 +12005,49 @@ When TURN-OFF evaled non-nil, then run BODY directly."
`(if ,turn-off ,(entropy/emacs-macroexp-progn body)
(save-mark-and-excursion (save-match-data ,@body)))))

(eval-and-compile
(cl-defmacro entropy/emacs-save-memrconds
(&rest
body
&key
save-match-data save-mark
save-excursion save-restriction
&allow-other-keys)
"Arrange BODY within `save-match-data', `save-excursion',
`save-mark' and `save-restriction' according to
each named as is optional key's non-nil value if needed.

Since we can not save the mark while allow the buffer excursion
operation at the same time, thus `save-mark's non-nil state will
cover whatever value of `save-excursion' is i.e. using
`save-mark-and-excursion' for saving the mark which will also
save the excursion."
(let ((body
(entropy/emacs-get-plist-body body t)))
(macroexp-let2* ignore
((svmd save-match-data) (svexr save-excursion)
(svrt save-restriction) (svmk save-mark)
(rbody nil) (bsmd nil) (bsr nil) (tbody nil))
`(let (_)
(if (not (or ,svmd ,svexr ,svrt ,svmk)) (progn ,@body)
(setq ,rbody (lambda nil ,@body))
(if (not ,svmd) (setq ,bsmd (lambda nil (funcall ,rbody)))
(setq ,bsmd (lambda nil (save-match-data (funcall ,rbody)))))
(if (not ,svrt) (setq ,bsr (lambda nil (funcall ,bsmd)))
(setq ,bsr (lambda nil (save-restriction (funcall ,bsmd)))))
(cond
((not (null ,svmk))
(entropy/emacs-setf-by-body ,tbody
(lambda nil
(save-mark-and-excursion (funcall ,bsr)))))
((not (null ,svexr))
(entropy/emacs-setf-by-body ,tbody
(lambda nil
(save-excursion (funcall ,bsr)))))
(t
(setq ,tbody (lambda nil (funcall ,bsr)))))
(funcall ,tbody)))))))

(defvar entropy/emacs-sync-var-dynamic-value--cache nil)
(defun entropy/emacs-sync-var-dynamic-value--regist
(avar bvar guard-func)
Expand Down
Loading

0 comments on commit f99052a

Please sign in to comment.