pkg update and first config fix

org-brain not working, add org-roam
This commit is contained in:
2022-12-19 23:02:34 +01:00
parent 02b3e07185
commit 82f05baffe
885 changed files with 356098 additions and 36993 deletions

View File

@@ -2,9 +2,9 @@
;; Copyright (C) 2020 Benjamin Levy - MIT/X11 License
;; Author: Benjamin Levy <blevy@protonmail.com>
;; Version: 0.4.0
;; Package-Version: 20220106.758
;; Package-Commit: 5b346068c346c4164f5e48e81d1e1bb285da8fd5
;; Version: 0.4.2
;; Package-Version: 20220714.2146
;; Package-Commit: c675563af3f9ab5558cfd5ea460e2a07477b0cfd
;; Description: Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them
;; Homepage: https://github.com/io12/org-fragtog
;; Package-Requires: ((emacs "27.1"))
@@ -37,9 +37,10 @@
;;; Code:
(require 'org)
(require 'org-element)
(defgroup org-fragtog nil
"Auto-toggle Org LaTeX fragments"
"Auto-toggle Org LaTeX fragments."
:group 'org-latex)
(defcustom org-fragtog-ignore-predicates nil
@@ -62,7 +63,7 @@ For example, adding `org-at-table-p' will ignore fragments inside tables."
"A minor mode that automatically toggles Org mode LaTeX fragment previews.
Fragment previews are disabled for editing when your cursor steps onto them,
and re-enabled when the cursor leaves."
nil nil nil
:init-value nil
;; Fix nil error in `org-element-context'
;; when using `org-fragtog' without Org mode.
@@ -73,8 +74,9 @@ and re-enabled when the cursor leaves."
(remove-hook 'post-command-hook #'org-fragtog--post-cmd t)))
(defvar-local org-fragtog--prev-frag nil
"Previous fragment that surrounded the cursor, or nil if the cursor was not
on a fragment. This is used to track when the cursor leaves a fragment.")
"Previous fragment that surrounded the cursor.
If the cursor was not on a fragment, this variable is nil. This is used to
track when the cursor leaves a fragment.")
(defvar-local org-fragtog--prev-point nil
"Value of point from before the most recent command.")
@@ -84,7 +86,8 @@ on a fragment. This is used to track when the cursor leaves a fragment.")
(defun org-fragtog--post-cmd ()
"This function is executed by `post-command-hook' in `org-fragtog-mode'.
It handles toggling fragments depending on whether the cursor entered or exited them."
It handles toggling fragments depending on whether the cursor entered or exited
them."
(let*
;; Previous fragment
((prev-frag (or org-fragtog--prev-frag
@@ -100,14 +103,14 @@ It handles toggling fragments depending on whether the cursor entered or exited
(goto-char org-fragtog--prev-point)
(org-fragtog--cursor-frag)))))
;; Previous fragment's start position
(prev-frag-start-pos (car (org-fragtog--frag-pos prev-frag)))
(prev-frag-start-pos (org-fragtog--frag-start prev-frag))
;; Current fragment
(cursor-frag (org-fragtog--cursor-frag))
;; The current fragment didn't change
(frag-same (equal
;; Fragments are considered the same if they have the same
;; start position
(car (org-fragtog--frag-pos cursor-frag))
(org-fragtog--frag-start cursor-frag)
prev-frag-start-pos))
;; The current fragment changed
(frag-changed (not frag-same))
@@ -125,8 +128,7 @@ It handles toggling fragments depending on whether the cursor entered or exited
;; Enable fragment if cursor left it after a timed disable
;; and the fragment still exists
(when (and frag-at-prev-pos
(not (org-fragtog--overlay-in-p
(org-fragtog--frag-pos frag-at-prev-pos))))
(not (org-fragtog--frag-enabled frag-at-prev-pos)))
(org-fragtog--enable-frag frag-at-prev-pos))
;; Cancel and expire timer
(when org-fragtog--timer
@@ -144,15 +146,30 @@ It handles toggling fragments depending on whether the cursor entered or exited
(setq org-fragtog--prev-point (point))))
(defun org-fragtog--frag-enabled (frag)
"Return whether FRAG is enabled.
A fragment is enabled when it has a preview image overlay in the buffer."
(org-fragtog--overlay-in-p (org-fragtog--frag-start frag)
(org-fragtog--frag-end frag)))
(defun org-fragtog--overlay-in-p (range)
"Return whether there is a fragment overlay in RANGE.
The RANGE parameter is a cons of start and end positions."
(defun org-fragtog--overlay-in-p (start-pos end-pos)
"Return whether there is a fragment overlay between START-POS and END-POS."
(seq-find (lambda (overlay)
(equal (overlay-get overlay 'org-overlay-type)
'org-latex-overlay))
(overlays-in (car range) (cdr range))))
(overlays-in start-pos end-pos)))
(defun org-fragtog--frag-start (frag)
"Return the position of the beginning of FRAG."
(org-element-property :begin frag))
(defun org-fragtog--frag-end (frag)
"Return the position of the end of FRAG."
;; Normally org-mode considers whitespace after an element as part of the
;; element. Avoid this behavior and consider trailing whitespace as outside
;; the fragment.
(- (org-element-property :end frag)
(org-element-property :post-blank frag)))
(defun org-fragtog--cursor-frag ()
"Return the fragment currently surrounding the cursor.
@@ -162,18 +179,10 @@ return nil."
(let*
;; Element surrounding the cursor
((elem (org-element-context))
;; Type of element surrounding the cursor
(elem-type (nth 0 elem))
;; List of fragment's properties
(elem-plist (nth 1 elem))
;; A LaTeX fragment or environment is surrounding the cursor
(elem-is-latex (and (member elem-type '(latex-fragment latex-environment))
;; Normally org-mode considers whitespace after an
;; element as part of the element.
;; Avoid this behavior and consider trailing
;; whitespace as outside the fragment.
(< (point) (- (plist-get elem-plist :end)
(plist-get elem-plist :post-blank)))))
(elem-is-latex (and (member (org-element-type elem)
'(latex-fragment latex-environment))
(< (point) (org-fragtog--frag-end elem))))
;; Whether the fragment should be ignored
(should-ignore (run-hook-with-args-until-success
'org-fragtog-ignore-predicates)))
@@ -188,14 +197,43 @@ return nil."
;; The fragment must be disabled before `org-latex-preview', since
;; `org-latex-preview' only toggles, leaving no guarantee that it's enabled
;; afterwards.
(org-fragtog--disable-frag frag)
(save-excursion
(org-fragtog--disable-frag frag))
;; Move to fragment and enable
(save-excursion
(goto-char (car
(org-fragtog--frag-pos frag)))
(goto-char (org-fragtog--frag-start frag))
;; Org's "\begin ... \end" style LaTeX fragments consider whitespace
;; before the fragment as part of the fragment.
;; Some users overload `org-latex-preview' to functions with similar functionality,
;; such as `math-preview-at-point' from the `math-preview' package on MELPA.
;; These alternatives might get confused if they're asked to enable a fragment at
;; point when point is on whitespace before the fragment.
;; So, advance to the nearest non-whitespace character before enabling.
(re-search-forward "[^ \t]")
(ignore-errors (org-latex-preview))))
(defun org-fragtog--set-point-after-disable-frag (frag)
"Set point to where it should be after FRAG was disabled.
If point decreases and enters a fragment from the end, disabling it, then point
should move to the end of the fragment. If point moved up one line, its column
should be maintained."
(when (and ;; There has to be a prev-point.
org-fragtog--prev-point
;; Only move to the end of the fragment if it's closer to the
;; prev-point location than the start of the fragment is.
(< (abs (- org-fragtog--prev-point (org-fragtog--frag-end frag)))
(abs (- org-fragtog--prev-point (org-fragtog--frag-start frag)))))
(let ((prev-point-column (save-excursion
(goto-char org-fragtog--prev-point)
(current-column))))
;; Move to the line where the fragment ends while preserving the point
;; column.
(goto-char (1- (org-fragtog--frag-end frag)))
(when (/= (line-number-at-pos org-fragtog--prev-point)
(line-number-at-pos))
(move-to-column prev-point-column)))))
(defun org-fragtog--disable-frag (frag &optional renew)
"Disable the Org LaTeX fragment preview for the fragment FRAG.
If RENEW is non-nil, renew the fragment at point."
@@ -209,17 +247,9 @@ If RENEW is non-nil, renew the fragment at point."
;; There may be nothing at the adjusted point
(when frag
(let
((pos (org-fragtog--frag-pos frag)))
(org-clear-latex-preview (car pos)
(cdr pos)))))
(defun org-fragtog--frag-pos (frag)
"Get the position of the fragment FRAG.
Return a cons of the begin and end positions."
(cons
(org-element-property :begin frag)
(org-element-property :end frag)))
(org-clear-latex-preview (org-fragtog--frag-start frag)
(org-fragtog--frag-end frag))
(org-fragtog--set-point-after-disable-frag frag)))
(provide 'org-fragtog)