[PATCH] ob-tangle: Add flag to optionally remove files before writing

2024-01-23 Thread Olivier Lischer
In December last year was a change introduced, that a file should not be
removed before
tangling (https://lists.gnu.org/r/emacs-orgmode/2021-05/msg00337.html).
In an older bug report
(https://lists.gnu.org/r/emacs-orgmode/2021-05/msg00337.html)
the decision was to remove the file before writing.
I added a variable to switch between both behaviors.

Any feedback or advice is welcome.

>From 4f2f2a0dcca82a934144636da478a9243e514f66 Mon Sep 17 00:00:00 2001
From: Olivier Lischer 
Date: Tue, 23 Jan 2024 21:02:20 +0100
Subject: [PATCH] ob-tangle: Add flag to optionally remove files before writing

* lisp/ob-tangle.el: Add variable
`org-babel-tangle-remove-file-before-write'.
(org-babel-tangle): Remove file before writing when
`org-babel-tangle-remove-file-before-write' is set.

The variable `org-babel-tangle-remove-file-before-write' adds support
for the current and old behaviour of `org-babel-tangle'.

TINYCHANGE
---
 etc/ORG-NEWS  |  4 
 lisp/ob-tangle.el | 12 +---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f537486d4..c7c3ee264 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -800,6 +800,10 @@ Completion is enabled for links to man pages added using ~org-insert-link~:
 =C-c C-l man RET emacscl TAB= to get =emacsclient=.  Of course, the ~ol-man~
 library should be loaded first.
 
+*** =ob-tangle.el=: Add flag to optionally remove files before writing
+
+When ~org-babel-tangle-remove-file-before-write~ is set to ~t~ the file is removed before writing.
+
 ** New functions and changes in function arguments
 *** New API functions to store data within ~org-element-cache~
 
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 72089a9a5..37fcd194c 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -166,6 +166,12 @@ read-write permissions for the user, read-only for everyone else."
   :package-version '(Org . "9.6")
   :type 'integer)
 
+(defcustom org-babel-tangle-remove-file-before-write nil
+  "Prevents the deletion of an existing file before tangle"
+  :group 'org-babel-tangle
+  :package-version '(Org . "9.7")
+  :type 'boolean)
+
 (defun org-babel-find-file-noselect-refresh (file)
   "Find file ensuring that the latest changes on disk are
 represented in the file."
@@ -313,9 +319,9 @@ matching a regular expression."
   (compare-buffer-substrings
nil nil nil
tangle-buf nil nil)))
- ;; We do not erase, but overwrite previous file
- ;; to preserve any existing symlinks.
-		 (write-region nil nil file-name)
+ (when (and (file-exists-p file-name) org-babel-tangle-remove-file-before-write)
+   (delete-file file-name))
+ (write-region nil nil file-name)
 		 (mapc (lambda (mode) (set-file-modes file-name mode)) modes))
(push file-name path-collector))
 	 (if (equal arg '(4))
-- 
2.43.0



[BUG] org-internal links broken by defaulting org-open-link-functions to org-ctags-find-tag [9.7-pre (release_9.6.14-1020-g80ce61 @ /Users/kevin/emacs_configs/vanilla/.emacs.d/straight/build/org/)]

2024-01-23 Thread Kevin Safford
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


When either performing a mouse click or pressing RET on an org-mode
link, instead of navigating to the specified destination, I am prompted
to specify a ctags file.

This occurs for all variety of links: radio targets, internal links to
headlines, external links using, e.g. file: and as far as I can tell,
any sort of link whatsoever.

This seems to be the wrong choice for the default and results in
confusing behavior that was quite difficult to understand and resolve.

Emacs  : GNU Emacs 29.0.90 (build 1, x86_64-apple-darwin21.6.0, NS
appkit-2113.60 Version 12.6.5 (Build 21G531))
 of 2023-05-08
Package: Org mode version 9.7-pre (release_9.6.14-1020-g80ce61 @
/Users/kevin/emacs_configs/vanilla/.emacs.d/straight/build/org/)


Re: [BUG] org-lint tells to move #+name to wrong place in results block

2024-01-23 Thread gerard . vermeulen



On 22.01.2024 19:59, Ihor Radchenko wrote:

gerard.vermeu...@posteo.net writes:


FR: would it be possible to resolve such links?


What is the purpose? Why not simply leaving the result name same as 
the

source block?


I have Python "IN" blocks generating Python "OUT" blocks that may end 
up

on different pages after exporting to LaTeX and PDF.
The FR would allow to link always to the correct page.


Patches welcome.


This patch completes my "Make an org-lint warning more helpful" patch.

I have found that CAPTION keywords  in the "name-result-example" in the
manual are essential to produce correct links.

In case the relevant blocks have e.g. ":exports both", Org handles
this, but:
1. HTML export requires captions to produce links with unequivocal
   "link texts" which are numbers in the HTML output.
2. LaTeX export requires captions to produce captions with labels like
   =\caption{\label{path}desc}=.
Tested on example below:

Produced by listing [[IN]].

#+caption: Results block
#+name: OUT
#+RESULTS: IN
#+begin_src emacs-lisp :exports code
6
#+end_src

#+caption: Source block
#+header: :wrap "src emacs-lisp :exports code"
#+name: IN
#+begin_src emacs-lisp :exports both
6
#+end_src

Listing [[IN]] produces listing [[OUT]].

From inspecting HTML or LaTeX output using this example
for the difference between with and without captions it is
easy to see that only with captions the output is correct.

The patch tries to add this information to the manual.

Regards -- Gerard


0001-doc-org-manual-Add-CAPTION-keywords-to-named-results.patch
Description: Binary data


Re: [PATCH] testing: Delete duplicate tests

2024-01-23 Thread Ilya Chernyshov
Ihor Radchenko  writes:

> It has been a while since the last update in this thread.
> Ilya, do you need any help with the patch?

Hi, here is the updated patch.

>From 2385ba08a89f2966a6d71f92e8693e7def33e3fe Mon Sep 17 00:00:00 2001
From: Ilya Chernyshov 
Date: Mon, 22 Jan 2024 01:33:56 +0600
Subject: [PATCH] Add testing/lisp/test-duplicates-detector.el

* testing/lisp/test-duplicates-detector.el: Add test unit that checks for
duplicate ert-deftests and forms inside of them.

* testing/lisp/test-org.el (test-org/file-contents): Delete duplicate
`should-' form.

* testing/lisp/test-ob-lob.el (test-ob-lob/call-with-header-arguments,
test-ob-lob/do-not-eval-lob-lines-in-example-blocks-on-export,
test-ob-lob/caching-call-line, test-ob-lob/named-caching-call-line,
test-ob/just-one-results-block): Ignore duplicate forms via
`org-test-ignore-duplicate'

* testing/lisp/test-ob.el (test-ob/just-one-results-block): Ignore
duplicate forms via `org-test-ignore-duplicate'

* testing/lisp/test-ob-R.el (test-ob-R/results-file): Ignore
duplicate forms via `org-test-ignore-duplicate'.

* testing/lisp/test-ob-haskell-ghci.el (ob-haskell/session-named-none-means-one-shot-sessions): Ignore
duplicate forms via `org-test-ignore-duplicate'.

* testing/lisp/test-ob.el
(test-ob/inline-src_blk-default-results-replace-line-1,
test-ob/inline-src_blk-default-results-replace-line-2,
test-ob/inline-src_blk-manual-results-replace,
test-ob/inline-src_blk-results-silent, test-ob/just-one-results-block,
test-ob/remove-inline-result, test-ob/goto-named-src-block): Ignore
duplicate forms via `org-test-ignore-duplicate'.

* testing/lisp/test-org-agenda.el (test-org-agenda/property-timestamp,
test-org-agenda/sticky-agenda-filter-preset): Ignore
duplicate forms via `org-test-ignore-duplicate'

* testing/lisp/test-org-element.el (test-org-element/cache-headline):
Ignore duplicate forms via `org-test-ignore-duplicate'

* testing/lisp/test-org-fold.el (test-org-fold/set-visibility-according-to-property): Ignore duplicate
forms via `org-test-ignore-duplicate'

* testing/lisp/test-org-list.el (test-org-list/list-navigation,
test-org-list/move-item-down, test-org-list/move-item-up): Ignore duplicate
forms via `org-test-ignore-duplicate'

* testing/lisp/test-org-src.el (test-org-src/basic): Ignore duplicate
forms via `org-test-ignore-duplicate'

* testing/lisp/test-org-table.el (test-org-table/org-at-TBLFM-p,
test-org-table/org-table-TBLFM-begin,
test-org-table/org-table-TBLFM-begin-for-multiple-TBLFM-lines,
test-org-table/org-table-TBLFM-begin-for-pultiple-TBLFM-lines-blocks):
Ignore duplicate forms via `org-test-ignore-duplicate'

* testing/lisp/test-org.el (test-org/goto-sibling,
test-org/backward-element, test-org/up-element,
test-org/org-ctrl-c-ctrl-c, test-org/forward-element): Ignore duplicate
forms via `org-test-ignore-duplicate'
---
 testing/lisp/test-duplicates-detector.el | 316 +++
 testing/lisp/test-ob-R.el|   5 +-
 testing/lisp/test-ob-haskell-ghci.el |   3 +-
 testing/lisp/test-ob-lob.el  |  87 ---
 testing/lisp/test-ob.el  | 113 
 testing/lisp/test-ol.el  |  35 +--
 testing/lisp/test-org-agenda.el  |   9 +-
 testing/lisp/test-org-element.el |  18 +-
 testing/lisp/test-org-fold.el|  29 ++-
 testing/lisp/test-org-list.el|  31 ++-
 testing/lisp/test-org-src.el |   3 +-
 testing/lisp/test-org-table.el   | 117 -
 testing/lisp/test-org.el |  38 ++-
 13 files changed, 568 insertions(+), 236 deletions(-)
 create mode 100644 testing/lisp/test-duplicates-detector.el

diff --git a/testing/lisp/test-duplicates-detector.el b/testing/lisp/test-duplicates-detector.el
new file mode 100644
index 0..d39092a9e
--- /dev/null
+++ b/testing/lisp/test-duplicates-detector.el
@@ -0,0 +1,316 @@
+;;; test-duplicates-detector.el --- Tests for finding duplicates in Org tests  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023  Ilya Chernyshov
+;; Authors: Ilya Chernyshov 
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see .
+;;
+;;; Commentary:
+
+;; Unit tests that check for duplicate forms and tests in all Org test files.
+
+;; Forms are considered duplicate if they:
+
+;; 1. are `equal-including-properties',
+;; 2. have the same nesting 

Re: [FR] 'org-columns-next-allowed-value' for 'summary-checkbox'es functions should have 'intermediate state' '[-]'

2024-01-23 Thread Sławomir Grochowski
Thank you for asking.
Yes, I would be interested.
I will prepare a patch.

Regards,
Sławomir Grochowski

On Tue, Jan 16, 2024 at 4:47 PM Ihor Radchenko  wrote:

> Ihor Radchenko  writes:
>
> >> What do you think?
> >
> > I think that your use-case is not necessarily common enough to change
> > the defaults. But we can introduce a defcustom here. Patches welcome!
>
> Sławomir, would you be interested to submit a patch here?
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at .
> Support Org development at ,
> or support my work at 
>


[PATCH] doc/org-manual.org: update Checkboxes and TODO items cookie statistics

2024-01-23 Thread Sławomir Grochowski
Dear All,

I'm sending you some updates to the ORG manual.
I'm sorry there's a lot of changes in this one patch.
If it's too much, I think I could break the changes into two commits:

First, move the 'Checkboxes' section under 'TODO Items' to '2 Document
Structure' -> '2.6 Plain Lists' -> '2.6.2 Checkboxes' because 'Checkbox'
can only exist in plain list items.
Second, all other updates -> about Checkboxes and TODO items cookie
statistics.

What do you think?

Patch in the attachment.
Thank you for the code review.
Now please help me find everything that can be improved in this patch.

Regards,
Sławomir Grochowski
From 0e7f14b7dc8474510993d1d9a4dd75bef7d7c12e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C5=82awomir=20Grochowski?= 
Date: Sun, 14 Jan 2024 21:25:32 +0100
Subject: [PATCH] doc/org-manual.org: update Checkboxes and TODO items cookie
 statistics

* doc/org-manual.org: move Checkboxes to Plain Lists, create separate
entries about Statics Cookie for TODO items and Checkboxes
---
 doc/org-manual.org | 483 +
 1 file changed, 311 insertions(+), 172 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index c332f90f1..9949236ee 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -1105,6 +1105,11 @@ additional structure.  They also provide a way to create lists of
 checkboxes (see [[*Checkboxes]]).  Org supports editing such lists, and
 every exporter (see [[*Exporting]]) can parse and format them.
 
+*** Plain Lists types
+:PROPERTIES:
+:DESCRIPTION: Ordered lists, unordered lists, and description lists.
+:END:
+
 Org knows ordered lists, unordered lists, and description lists.
 
 #+attr_texinfo: :indic @bullet
@@ -1308,6 +1313,259 @@ to disable them individually.
   Sort the plain list.  Prompt for the sorting method: numerically,
   alphabetically, by time, or by custom function.
 
+*** Checkboxes
+:PROPERTIES:
+:DESCRIPTION: Add checkbox to plain list item.
+:END:
+#+cindex: checkboxes
+
+#+vindex: org-list-automatic-rules
+Every item in a plain list[fn:17] (see [[*Plain Lists]]) can be made into
+a checkbox by starting it with the string =[ ]=.  This feature is
+similar to TODO items (see [[*TODO Items]]), but is more lightweight.
+Checkboxes are not included into the global TODO list, so they are
+often great to split a task into a number of simple steps.  Or you can
+use them in a shopping list.
+
+Here is an example of a checkbox list:
+
+#+begin_example
+  - [-] call people
+- [ ] Peter
+- [X] Sarah
+- [ ] Sam
+  - [X] order food
+  - [ ] think about what music to play
+  - [X] talk to the neighbors
+#+end_example
+
+ Checkboxes states
+:PROPERTIES:
+:DESCRIPTION: Not checked, partially checked and checked.
+:END:
+
+A checkbox can be in one of the three states:
+1. not checked =[ ]=
+2. partially checked =[-]=
+3. checked =[X]=
+
+Checkboxes work hierarchically, so if a checkbox item has children
+that are checkboxes, toggling one of the children checkboxes makes the
+parent checkbox reflect if none, some, or all of the children are
+checked.
+
+If all child checkboxes are not checked, the parent checkbox is also not checked.
+#+begin_example
+- [ ] call people
+  - [ ] Peter
+  - [ ] Sarah
+#+end_example
+
+If some but not all child checkboxes are checked, the parent checkbox is partially checked.
+#+begin_example
+- [-] call people
+  - [X] Peter
+  - [ ] Sarah
+#+end_example
+
+If all child checkboxes are checked, the parent checkbox is also checked.
+#+begin_example
+- [X] call people
+  - [X] Peter
+  - [X] Sarah
+#+end_example
+
+#+cindex: blocking, of checkboxes
+#+cindex: checkbox blocking
+#+cindex: @samp{ORDERED}, property
+If the current outline node has an =ORDERED= property, checkboxes must
+be checked off in sequence, and an error is thrown if you try to check
+off a box while there are unchecked boxes above it.
+
+ Checkboxes commands
+- {{{kbd(C-c C-c)}}} (~org-toggle-checkbox~) ::
+
+  #+kindex: C-c C-c
+  #+findex: org-toggle-checkbox
+  Toggle checkbox status or---with prefix argument---checkbox presence
+  at point.  With a single prefix argument, add an empty checkbox or
+  remove the current one[fn:: {{{kbd(C-u C-c C-c)}}} on the /first/
+  item of a list with no checkbox adds checkboxes to the rest of the
+  list.].  With a double prefix argument, set it to =[-]=, which is
+  considered to be an intermediate state.
+
+- {{{kbd(C-c C-x C-b)}}} (~org-toggle-checkbox~) ::
+
+  #+kindex: C-c C-x C-b
+  Toggle checkbox status or---with prefix argument---checkbox presence
+  at point.  With double prefix argument, set it to =[-]=, which is
+  considered to be an intermediate state.
+
+  - If there is an active region, toggle the first checkbox in the
+region and set all remaining boxes to the same status as the
+first.  With a prefix argument, add or remove the checkbox for all
+items in the region.
+
+  - If point is in a headline, toggle checkboxes in the region between
+this 

Re: [PATCH] Make an org-lint warning more helpful

2024-01-23 Thread gerard . vermeulen



On 22.01.2024 19:59, Ihor Radchenko wrote:

gerard.vermeu...@posteo.net writes:


FR: would it be possible to resolve such links?


What is the purpose? Why not simply leaving the result name same as 
the

source block?


I have Python "IN" blocks generating Python "OUT" blocks that may end 
up

on different pages after exporting to LaTeX and PDF.
The FR would allow to link always to the correct page.


Patches welcome.
Another option is :post argument that will add the necessary #+name.


I see that my FR is already an Org feature.

Attached patch makes the relevant org-lint warning more helpful for 
fixing

user's Org buffers.

I still have to think about your ":post argument" option to and #+name.

Regards -- Gerard



0001-Make-an-org-lint-warning-more-helpful.patch
Description: Binary data