Compare commits

...

5 Commits

Author SHA1 Message Date
TEC 8f1d75ae1b
---END PERSONAL NOPUSH DIVIDER---
--
2.42.0
2024-04-16 20:07:28 +08:00
TEC 2a78c11a96
NOPUSH org: Don't fill displayed equations in text
* list/org.el (org-fill-element): If a displayed equation (\[ ... \])
starts on its own line, it should not be filled into the rest of the
text. I.e.,

some nice text
\[
  1+1=2
\]
more text.

should not become,

some nice text \[ 1+1=3 \] more text.

While the above example may not look bad, with non-trivial equations
this can become quite messy.
2024-04-16 20:07:28 +08:00
TEC 8d3909de66
NOPUSH org-src: Prettify inline results
* lisp/org.el (org-inline-src-prettify-results):

* lisp/org-src.el (org-fontify-inline-src-blocks-1):
2024-04-16 20:07:28 +08:00
TEC 9183d8e6ff
---NOPUSH PERSONAL DIVIDER---
--
2.42.0
2024-04-16 20:07:28 +08:00
Karthik Chikmagalur f8c1678317
org-latex-preview: Fix live previews org-src setup
* lisp/org-latex-preview.el (org-latex-preview-live--src-buffer-setup):
Ensure that live LaTeX previews of org-src buffer contents are created
in the src buffer.  Since this runs on a timer, the active buffer can be
different from the org-src LaTeX buffer when the preview run fires.
Ensure that `org-element-context' is not called from the org-src buffer
by setting the element type persistently when it is set up.
2024-04-16 20:07:08 +08:00
3 changed files with 96 additions and 35 deletions

View File

@ -1223,54 +1223,62 @@ This is meant to be called via `org-src-mode-hook'."
(setq-local org-latex-preview-live--generator
(thread-first
(lambda (&rest _)
(let* ((content
(string-trim (buffer-substring-no-properties
(point-min) (point-max)))))
(with-current-buffer org-buf
(org-latex-preview-place
org-latex-preview-process-default
(list (list (overlay-start orig-ov)
(overlay-end orig-ov)
content))
numbering-offsets))))
(when (eq (current-buffer) src-buf)
(let* ((content
(string-trim (buffer-substring-no-properties
(point-min) (point-max)))))
(with-current-buffer org-buf
(org-latex-preview-place
org-latex-preview-process-default
(list (list (overlay-start orig-ov)
(overlay-end orig-ov)
content))
numbering-offsets)))))
(org-latex-preview-live--throttle)
(org-latex-preview-live--debounce
org-latex-preview-live-debounce)))
(add-hook 'after-change-functions org-latex-preview-live--generator 90 'local))
;; Source Org buffer not visible: display live previews in org-src buffer
;; Set the element type ahead of time since we cannot call
;; org-element-context in the org-src buffer
(setq org-latex-preview-live--element-type
(with-current-buffer org-buf
(or (and (string-prefix-p
"\\[" (org-element-property :value element))
'latex-environment)
(org-element-type element))))
;; Show live preview if available
(org-latex-preview-live--ensure-overlay ov)
;; Set up hooks for live preview updates in the org-src buffer
(let* ((element-type
(with-current-buffer org-buf
(or (and (string-prefix-p
"\\[" (org-element-property :value element))
'latex-environment)
(org-element-type element))))
(preview-clearout-func
(lambda (ov)
(org-latex-preview-live--clearout ov)
(setq org-latex-preview-live--element-type element-type))))
;; Set the element type ahead of time since we cannot call
;; org-element-context in the org-src buffer
(setq org-latex-preview-live--element-type element-type)
(add-hook 'org-latex-preview-overlay-close-functions
preview-clearout-func nil 'local))
(add-hook 'org-latex-preview-overlay-open-functions
#'org-latex-preview-live--ensure-overlay nil 'local)
(add-hook 'org-latex-preview-overlay-update-functions
#'org-latex-preview-live--update-overlay
nil 'local)
#'org-latex-preview-live--update-overlay nil 'local)
(setq-local org-latex-preview-live--generator
(thread-first
(lambda (&rest _)
(org-latex-preview-place
org-latex-preview-process-default
(list (list (save-excursion (goto-char (point-min))
(skip-chars-forward "\n \t\r")
(point))
(save-excursion (goto-char (point-max))
(skip-chars-backward "\n \t\r")
(point))))
numbering-offsets preamble))
(when (eq (current-buffer) src-buf)
(org-latex-preview-place
org-latex-preview-process-default
(list (list (save-excursion (goto-char (point-min))
(skip-chars-forward "\n \t\r")
(point))
(save-excursion (goto-char (point-max))
(skip-chars-backward "\n \t\r")
(point))))
numbering-offsets preamble)))
(org-latex-preview-live--throttle)
(org-latex-preview-live--debounce
org-latex-preview-live-debounce)))
(add-hook 'org-latex-preview-overlay-open-functions #'org-latex-preview-live--ensure-overlay nil 'local)
(add-hook 'org-latex-preview-overlay-close-functions #'org-latex-preview-live--clearout nil 'local)
(add-hook 'after-change-functions org-latex-preview-live--generator 90 'local)))
(add-hook 'after-change-functions org-latex-preview-live--generator 90 'local)
;; Show live preview if available
(org-latex-preview-live--ensure-overlay ov)))
;; Turn on auto-mode behavior in the org-src buffer
(add-hook 'pre-command-hook #'org-latex-preview-auto--handle-pre-cursor nil 'local)
(add-hook 'post-command-hook #'org-latex-preview-auto--handle-post-cursor nil 'local)))))

View File

@ -805,9 +805,42 @@ as `org-src-fontify-natively' is non-nil."
(font-lock-append-text-property
(1+ pt) (1- (point)) 'face 'org-inline-src-block)))
(add-face-text-property (1- (point)) (point) '(org-inline-src-block shadow))
(setq pt (point)))))
(setq pt (point)))
(when (and org-inline-src-prettify-results
(re-search-forward "\\= {{{results(" limit t))
(font-lock-append-text-property pt (1+ pt) 'face 'org-inline-src-block)
(goto-char pt))))
t)))
(defun org-fontify-inline-src-results (limit)
"Apply prettify-symbols modifications to inline results blocks.
Performed according to `org-inline-src-prettify-results'."
(when (and org-inline-src-prettify-results
(re-search-forward "{{{results(\\(.+?\\))}}}" limit t))
(remove-list-of-text-properties (match-beginning 0) (point)
'(composition
prettify-symbols-start
prettify-symbols-end))
(font-lock-append-text-property (match-beginning 0) (match-end 0)
'face 'org-block)
(let ((start (match-beginning 0)) (end (match-beginning 1)))
(with-silent-modifications
(compose-region start end (if (eq org-inline-src-prettify-results t)
"(" (car org-inline-src-prettify-results)))
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))
(let ((start (match-end 1)) (end (point)))
(with-silent-modifications
(compose-region start end (if (eq org-inline-src-prettify-results t)
")" (cdr org-inline-src-prettify-results)))
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))
t))
(defun org-toggle-inline-results-display ()
"Toggle the literal or contracted display of inline src blocks results."
(interactive)
(setq org-inline-src-prettify-results (not org-inline-src-prettify-results))
(org-restart-font-lock))
;;; Escape contents

View File

@ -5243,6 +5243,15 @@ by a #."
:version "24.1"
:group 'org-appearance)
(defcustom org-inline-src-prettify-results t
"Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.
Either t or a cons cell of strings which are used as substitutions
for the start and end of inline results, respectively."
:type '(choice boolean (cons string string))
:package-version '(Org . "9.5")
:group 'org-appearance
:group 'org-babel)
(defun org-fontify-meta-lines-and-blocks (limit)
(condition-case-unless-debug nil
(org-fontify-meta-lines-and-blocks-1 limit)
@ -19392,12 +19401,23 @@ a footnote definition, try to fill the first paragraph within."
(save-excursion
(goto-char beg)
(let ((cuts (list beg)))
;; Cut fill on line breaks.
(while (re-search-forward "\\\\\\\\[ \t]*\n" end t)
(when (org-element-type-p
(save-excursion (backward-char)
(org-element-context))
'line-break)
(push (point) cuts)))
;; Cut fill on displayed equations.
(while (re-search-forward "^[ \t]*\\\\\\[" end t)
(let ((el (org-element-context)))
(when (eq 'latex-fragment (org-element-type el))
(setf cuts (append
(list (org-element-property :end el)
(- (org-element-property :end el) 2)
(+ (org-element-property :begin el) 2)
(org-element-property :begin el))
cuts)))))
(dolist (c (delq end cuts))
(fill-region-as-paragraph c end justify)
(setq end c))))