Skip to content

Commit eb70d42

Browse files
committed
feat(attach): add org-attach feature
The implementation follows the Emacs implementation in spirit, with some additional separation of concerns: 1. the actual logic is implemented in `attach/core.lua`, with no concerns for UI or configuration; 2. `attach/init.lua` combines the core with UI and configuration and provides the public API; 3. `attach/ui.lua` contains any dialogs needed by the module; 4. `attach/fileops.lua` contains file operations that are provided to the Emacs implementation by the Emacs core (e.g. recursive copy/deletion of directories) 5. `attach/node.lua` provides an abstraction over headlines and whole files that is absent in the Emacs implementation 6. `attach/translate_id.lua` corresponds to the Emacs implementation's functions `org-attach-id-uuid-folder-format`, `org-attach-id-ts-folder-format`, and `org-attach-id-fallback-folder-format`. They are separated like this because referring to pre-defined functions in Lua is more difficult than in Emacs. To reduce complexity, the following functions are left unimplemented in this commit: - `org-attach-file-list` - `org-attach-expand` - `org-attach-follow` - `org-attach-complete-link` - `org-attach-reveal` - `org-attach-reveal-in-emacs` - `org-attach-open` - `org-attach-open-in-emacs` - `org-attach-delete-one` - `org-attach-delete-all` - `org-attach-sync` - `org-attach-archive-delete-maybe` - `org-attach-expand-links` - `org-attach-url` - `org-attach-dired-to-subtree`
1 parent b7bcb90 commit eb70d42

File tree

12 files changed

+1763
-0
lines changed

12 files changed

+1763
-0
lines changed

docs/configuration.org

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This page contains information about all configuration that can be provided to t
77
- [[#agenda-settings][Agenda settings]]
88
- [[#calendar-settings][Calendar settings]]
99
- [[#tags-settings][Tags settings]]
10+
- [[#attachment-settings][Attachments settings]]
1011
- [[#mappings][Mappings]]
1112
- [[#features][Features]]
1213
- [[#user-interface][User interface]]
@@ -1188,6 +1189,113 @@ Using the example above, setting this variable to ={'MYTAG'}=, second
11881189
and third headline would have only =CHILDTAG=, where =MYTAG= would not
11891190
be inherited.
11901191

1192+
** Attachments settings
1193+
:PROPERTIES:
1194+
:CUSTOM_ID: attachment-settings
1195+
:END:
1196+
1197+
*** org_attach_id_dir
1198+
:PROPERTIES:
1199+
:CUSTOM_ID: org_attach_id_dir
1200+
:END:
1201+
- Type: =string=
1202+
- Default: ='./data/'=
1203+
1204+
The directory where attachments are stored. If this is a relative path, it
1205+
will be interpreted relative to the directory where the Org file lives.
1206+
1207+
*** org_attach_auto_tag
1208+
:PROPERTIES:
1209+
:CUSTOM_ID: org_attach_auto_tag
1210+
:END:
1211+
- Type: =string=
1212+
- Default: ='ATTACH'=
1213+
1214+
Tag that is added automatically when attaching files to a headline.
1215+
1216+
*** org_attach_preferred_new_method
1217+
:PROPERTIES:
1218+
:CUSTOM_ID: org_attach_preferred_new_method
1219+
:END:
1220+
- Type: ='id'|'dir'|'ask'|false=
1221+
- Default: ='id'=
1222+
1223+
This setting is used when attaching files to nodes that have neither an
1224+
=ID= nor a =DIR= property.
1225+
1226+
- =id= - create and use an =ID= property
1227+
- =dir= - create and use a =DIR= property
1228+
- =ask= - ask the user which method to use
1229+
- =false= - don't create a property; the user has to define it explicitly before attaching files
1230+
1231+
*** org_attach_method
1232+
:PROPERTIES:
1233+
:CUSTOM_ID: org_attach_method
1234+
:END:
1235+
- Type: ='cp'|'mv'|'ln'|'lns'=
1236+
- Default: ='cp'=
1237+
1238+
The preferred method to add files to the attachment directory.
1239+
1240+
- =mv= - move (rename) the file
1241+
- =cp= - copy the file
1242+
- =ln= - create a hard link; not supported on all systems
1243+
- =lns= - create a symbol link; not supported on all systems; on Windows, this always creates a /junction/
1244+
1245+
*** org_attach_copy_directory_create_symlink
1246+
:PROPERTIES:
1247+
:CUSTOM_ID: org_attach_copy_directory_create_symlink
1248+
:END:
1249+
- Type: =boolean=
1250+
- Default: =false=
1251+
1252+
If =true=, whenever the attachments directory itself is a symlink, and it
1253+
is copied due to the [[https://orgmode.org/manual/Attachment-defaults-and-dispatcher.html*index-C_002dc-C_002da-s][set_directory]] or [[https://orgmode.org/manual/Attachment-defaults-and-dispatcher.html*index-C_002dc-C_002da-S][unset_directory]] action, copy the
1254+
symlink itself. The default is to treat the symlink transparently as
1255+
a directory.
1256+
1257+
*** org_attach_use_inheritance
1258+
:PROPERTIES:
1259+
:CUSTOM_ID: org_attach_use_inheritance
1260+
:END:
1261+
- Type: ='always'|'selective'|'never'=
1262+
- Default: ='selective'=
1263+
1264+
Attachment inheritance for the outline.
1265+
1266+
Enabling inheritance implies that running =attach= inside a node without
1267+
attachments will operate on the first parent headline that has an
1268+
attachment.
1269+
1270+
Possible values are:
1271+
1272+
- =always= - inherit attachments
1273+
- =selective= - respect [[#org_use_property_inheritance][org_use_property_inheritance]] for the properties =DIR= and =ID=
1274+
- =never= - don't inherit attachments
1275+
1276+
*** org_attach_id_to_path_function_list
1277+
:PROPERTIES:
1278+
:CUSTOM_ID: org_attach_id_to_path_function_list
1279+
:END:
1280+
- Type: =(string | fun(id: string): (string|nil))[]=
1281+
- Default: ={ 'uuid_folder_format', 'ts_folder_format', 'fallback_folder_format' }=
1282+
1283+
List of functions that are tried sequentially to derive an attachment path
1284+
from an =ID= property. The functions are called with a single =id= argument
1285+
until the return value is an existing folder. The ID format passed to the
1286+
functions is usually defined by [[#org_id_method][org_id_method]].
1287+
1288+
If no folder has been created yet for the given ID, then the first truthy
1289+
value defines the path of the folder to be created.
1290+
1291+
The default functions avoid putting all attachment directories directly
1292+
inside [[#org_attach_id_dir][org_attach_id_dir]]. Some file systems have performance issues in
1293+
such scenarios.
1294+
1295+
Be careful when changing this setting. If you remove a function, previously
1296+
created attachment folders may be no longer mapped correctly and Org may be
1297+
unable to detect them.
1298+
11911299
** Mappings
11921300
:PROPERTIES:
11931301
:CUSTOM_ID: mappings
@@ -2105,6 +2213,13 @@ See [[#clocking][Clocking]] for more details.
21052213
- Mapped to: =<leader>obt=
21062214
Tangle current file. See [[#extract-source-code-tangle][Extract source code (tangle)]] for more details.
21072215

2216+
**** org_attach
2217+
:PROPERTIES:
2218+
:CUSTOM_ID: org_attach
2219+
:END:
2220+
- Mapped to: =<Leader>o<C-A>=
2221+
Open the attach dispatcher. See [[#attachments][Attachments]] for more details.
2222+
21082223
**** org_show_help
21092224
:PROPERTIES:
21102225
:CUSTOM_ID: org_show_help
@@ -2863,6 +2978,22 @@ Running [[#org_babel_tangle][org_babel_tangle]] will create file =~/org/my_tangl
28632978
=print('Headline 1')=
28642979
=#+end_src=
28652980

2981+
*** Attachments
2982+
:PROPERTIES:
2983+
:CUSTOM_ID: attachments
2984+
:END:
2985+
2986+
There is almost complete support for file attachments (Orgmode link:
2987+
[[https://orgmode.org/manual/Attachments.html][Attachments]]). You can use [[#org_attach][org_attach]] to open the dispatcher and attach
2988+
files to an "attachment node" (either a headline or an entire org
2989+
file).
2990+
2991+
Attaching a file puts it in a directory associated with the attachment node.
2992+
Based on [[#org_attach_preferred_new_method][org_attach_preferred_new_method]], this either uses the =ID= or
2993+
the =DIR= property. See also [[#org_attach_id_dir][org_attach_id_dir]],
2994+
[[#org_attach_id_to_path_function_list][org_attach_id_to_path_function_list]] and [[#org_attach_use_inheritance][org_attach_use_inheritance]] on how
2995+
to further customize the attachments directory.
2996+
28662997
** User interface
28672998
:PROPERTIES:
28682999
:CUSTOM_ID: user-interface

0 commit comments

Comments
 (0)