emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Automatically use Heading Content as EXPORT_FILE_NAME?
@ 2022-04-26 15:54 Tim Visher
  2022-04-26 16:24 ` Tim Visher
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Visher @ 2022-04-26 15:54 UTC (permalink / raw)
  To: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 772 bytes --]

Hello Everyone,

Is  there a way to automatically use the text content of the current
Heading as the EXPORT_FILE_NAME? AFAICT there isn't.

I tend to do most of my Org writing in a few 'mono files' (like todo.org or
wiki.org). I then set my export options to default to subtree and visible
contents etc.

The resulting file is always named after the whole mono file though. Given
my usage pattern it would be awesome if it instead could default to the
current heading text.

Is that something others would be interested in? I'm currently going to
hack around it I think by simply making a function that updates the
EXPORT_FILE_NAME property with the current heading text.

Thanks in advance!

--

In Christ,

Timmy V.

https://blog.twonegatives.com
http://five.sentenc.es

[-- Attachment #2: Type: text/html, Size: 1103 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Automatically use Heading Content as EXPORT_FILE_NAME?
  2022-04-26 15:54 Automatically use Heading Content as EXPORT_FILE_NAME? Tim Visher
@ 2022-04-26 16:24 ` Tim Visher
  2022-04-27  2:27   ` Samuel Wales
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Visher @ 2022-04-26 16:24 UTC (permalink / raw)
  To: Emacs Org Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 676 bytes --]

On Tue, Apr 26, 2022 at 11:54 AM Tim Visher <tim.visher@gmail.com> wrote:

> I'm currently going to hack around it I think by simply making a function
> that updates the EXPORT_FILE_NAME property with the current heading text.
>

That's something like

```
(defun timvisher-org-set-export_file_name-property-to-heading-text
    ()
  (interactive)
  (org-set-property
   "EXPORT_FILE_NAME"
   (let ((stripped-heading
          (replace-regexp-in-string
           "[^-A-Za-z0-9_.~#+ ]"
           ""
           (substring-no-properties (org-get-heading t t t t)))))
     (substring-no-properties
      stripped-heading
      0
      (min (length stripped-heading) 250)))))
```

[-- Attachment #2: Type: text/html, Size: 1252 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Automatically use Heading Content as EXPORT_FILE_NAME?
  2022-04-26 16:24 ` Tim Visher
@ 2022-04-27  2:27   ` Samuel Wales
  0 siblings, 0 replies; 3+ messages in thread
From: Samuel Wales @ 2022-04-27  2:27 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

fwiw, what i do is export to a buffer, then write to a file whose name
is derived from the header.

(alpha-make-valid-path
                        (with-current-buffer org-buffer
(org-get-heading 'no-tags 'no-todo)))

(defun alpha-make-valid-path (s)
  "Make a string into a filesystem path."
  ;; see files.el for this and tramp
  (subst-char-in-string ?/ ?!
                         (replace-regexp-in-string "!" "!!" s)))

i think it might have some issues with long headers and some basename
limit on linux.  you seem to truncate for that.


On 4/26/22, Tim Visher <tim.visher@gmail.com> wrote:
> On Tue, Apr 26, 2022 at 11:54 AM Tim Visher <tim.visher@gmail.com> wrote:
>
>> I'm currently going to hack around it I think by simply making a function
>> that updates the EXPORT_FILE_NAME property with the current heading text.
>>
>
> That's something like
>
> ```
> (defun timvisher-org-set-export_file_name-property-to-heading-text
>     ()
>   (interactive)
>   (org-set-property
>    "EXPORT_FILE_NAME"
>    (let ((stripped-heading
>           (replace-regexp-in-string
>            "[^-A-Za-z0-9_.~#+ ]"
>            ""
>            (substring-no-properties (org-get-heading t t t t)))))
>      (substring-no-properties
>       stripped-heading
>       0
>       (min (length stripped-heading) 250)))))
> ```
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-27  2:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 15:54 Automatically use Heading Content as EXPORT_FILE_NAME? Tim Visher
2022-04-26 16:24 ` Tim Visher
2022-04-27  2:27   ` Samuel Wales

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).