Re: org-element-cache error when storing footnotes using capture buffer

2024-10-04 Thread Akash


Dear Maintainers,

I seem to have been able to solve this issue through some brute force debugging.
The problem emanates from when copying over the local variables, especially the 
`buffer-file-name' variable

The function definition `org-src--edit-element' contains a provision to make 
the said variable nil - but it is quickly reset during initialisation of the 
buffer just 1 line downstream. Moving the setq statement 4 lines below seems to 
solve the issue,

Herein I give the patch,

```
--- org-src.el  2024-10-04 15:54:11.357117268 +0530
+++ org-src-patched.el  2024-10-04 15:55:24.041730163 +0530
@@ -609,7 +609,6 @@
(let ((lf (eq type 'latex-fragment)))
   (unless preserve-ind (org-do-remove-indentation (and lf block-ind) 
lf)))
(set-buffer-modified-p nil)
-   (setq buffer-file-name nil)
;; Initialize buffer.
(when (functionp initialize)
  (let ((org-inhibit-startup t))
@@ -617,6 +616,7 @@
(funcall initialize)
  (error (message "Initialization fails with: %S"
  (error-message-string e))
+   (setq buffer-file-name nil)
;; Transmit buffer-local variables for exit function.  It must
;; be done after initializing major mode, as this operation
;; may reset them otherwise.

```

The following in .init can also be done by users not willing to patch the 
source file `org-src.el'

;; ---

(defun patch/org-src--edit-element (&rest args)
  (setq-local buffer-file-name nil))
(advice-add 'org-src--edit-element
:after
#'patch/org-src--edit-element)

;; ---


Thank you,
Akash P




[Bug?] Non-existent agenda file %s.

2024-03-28 Thread Akash Pal
I came across this flow of execution while trying to export a ghost
org-file to pdf, meaning that the file is 'created' through #'find-file but
not saved. While export the following backtrace is noted:

```
Debugger entered--entering a function:
* org-check-agenda-file("/home/akash/Desktop/test.org")
org-agenda-prepare-buffers(("/home/akash/Desktop/test.org"))
org-map-entries((lambda nil (org-set-tags (delete "attached"
(org-get-tags "attached")
custom/org-export-remove-attached-tag(latex)
org-export-as(latex nil nil nil (:output-file "org-exports/test/test.tex"))
org-export-to-file(latex "org-exports/test/test.tex" nil nil nil nil
nil org-latex-compile)
org-latex-export-to-pdf(nil nil nil nil)
org-export-dispatch(nil)
funcall-interactively(org-export-dispatch nil)
command-execute(org-export-dispatch)

```

I have provisions to call #'org-map-entries before export this triggers
#'org-agenda-prepare-buffers which finally calls #'org-check-agenda-files

This asks the user what to do with a non existent file

Non-existent agenda file %s. [R]emove from list or [A]bort?

*Problem*

I think this should not be called unless the file is part of
'org-agenda-files

I have resorted to advicing the function as follows:

```
;; Advice-Patch
;; if #'org-map-entries is called then #'org-check-agenda-file is
executed through #'org-agenda-prepare-buffers
;; issue: neither functions is relevant to non-agenda files, causes
bug asking user for extra input
;; Non-existent agenda file %s.  [R]emove from list or [A]bort?
;; see : 
https://github.com/bzg/org-mode/blob/ec5d76bce1434a54a9a529dbe250b09dc3c132c0/lisp/org.el#L15340
;; Possible solution: Do not call #'org-agenda-prepare-buffers for
non-agenda files => ~exist 'org-agenda-files

(defun my-org-agenda-prepare-buffers-advice (orig-func &rest args)
"Advice function to modify `org-agenda-prepare-buffers'.
It filters the FILES argument to ensure only agenda files are processed."
(let ((files (if (listp (car args)) (car args) nil)))
(when files
(setq files (seq-filter #'(lambda (file) (member file
org-agenda-files)) files)))
(apply orig-func (list files

(advice-add 'org-agenda-prepare-buffers :around
#'my-org-agenda-prepare-buffers-advice)
```

I don't know if this is a bug or something peculiar to my use case. Leaving
the solution for others to see and possibly advice further.

First posted on reddit r/emacs.
https://www.reddit.com/r/emacs/comments/1bnhz24/bug_nonexistent_agenda_file_s/


org-element-cache error when storing footnotes using capture buffer

2024-10-02 Thread Akash Pal
Suppose we have the following document

```
#+title: test-file

* This is h1

** This is h1.2

We introduce some text here

Then we narrow to this heading and introduce a footnote


* Another heading here so that footnote capture works
#+begin_src
(org-element-property :buffer (org-element-at-point))
#+end_src

* Footnotes
```

When we narrow to h1.2 (subtree) so that * Footnotes is not visible - after
adding the footnote, when we check

(org-element-property :buffer (org-element-at-point)) at any headline level
or anywhere
It returns nil - inplace of the # element it should return

This causes functions to fail that rely on this.

I am on Org mode version 9.8-pre (release_9.7.11-145-g28b631 -- the version
we get when we clone the git today (2024-10-03)

Thank you, let me know if you need any information in reproducing it.