Skip to content

Commit bfd56b3

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 9fdc30e commit bfd56b3

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]]
@@ -1201,6 +1202,113 @@ Using the example above, setting this variable to ={'MYTAG'}=, second
12011202
and third headline would have only =CHILDTAG=, where =MYTAG= would not
12021203
be inherited.
12031204

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

2229+
**** org_attach
2230+
:PROPERTIES:
2231+
:CUSTOM_ID: org_attach
2232+
:END:
2233+
- Mapped to: =<Leader>o<C-A>=
2234+
Open the attach dispatcher. See [[#attachments][Attachments]] for more details.
2235+
21212236
**** org_show_help
21222237
:PROPERTIES:
21232238
:CUSTOM_ID: org_show_help
@@ -2876,6 +2991,22 @@ Running [[#org_babel_tangle][org_babel_tangle]] will create file =~/org/my_tangl
28762991
=print('Headline 1')=
28772992
=#+end_src=
28782993

2994+
*** Attachments
2995+
:PROPERTIES:
2996+
:CUSTOM_ID: attachments
2997+
:END:
2998+
2999+
There is almost complete support for file attachments (Orgmode link:
3000+
[[https://orgmode.org/manual/Attachments.html][Attachments]]). You can use [[#org_attach][org_attach]] to open the dispatcher and attach
3001+
files to an "attachment node" (either a headline or an entire org
3002+
file).
3003+
3004+
Attaching a file puts it in a directory associated with the attachment node.
3005+
Based on [[#org_attach_preferred_new_method][org_attach_preferred_new_method]], this either uses the =ID= or
3006+
the =DIR= property. See also [[#org_attach_id_dir][org_attach_id_dir]],
3007+
[[#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
3008+
to further customize the attachments directory.
3009+
28793010
** User interface
28803011
:PROPERTIES:
28813012
:CUSTOM_ID: user-interface

0 commit comments

Comments
 (0)