Skip to content

Commit 88cadcd

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 2b91d9a commit 88cadcd

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

1136+
** Attachments settings
1137+
:PROPERTIES:
1138+
:CUSTOM_ID: attachment-settings
1139+
:END:
1140+
1141+
*** org_attach_id_dir
1142+
:PROPERTIES:
1143+
:CUSTOM_ID: org_attach_id_dir
1144+
:END:
1145+
- Type: =string=
1146+
- Default: ='./data/'=
1147+
1148+
The directory where attachments are stored. If this is a relative path, it
1149+
will be interpreted relative to the directory where the Org file lives.
1150+
1151+
*** org_attach_auto_tag
1152+
:PROPERTIES:
1153+
:CUSTOM_ID: org_attach_auto_tag
1154+
:END:
1155+
- Type: =string=
1156+
- Default: ='ATTACH'=
1157+
1158+
Tag that is added automatically when attaching files to a headline.
1159+
1160+
*** org_attach_preferred_new_method
1161+
:PROPERTIES:
1162+
:CUSTOM_ID: org_attach_preferred_new_method
1163+
:END:
1164+
- Type: ='id'|'dir'|'ask'|false=
1165+
- Default: ='id'=
1166+
1167+
This setting is used when attaching files to nodes that have neither an
1168+
=ID= nor a =DIR= property.
1169+
1170+
- =id= - create and use an =ID= property
1171+
- =dir= - create and use a =DIR= property
1172+
- =ask= - ask the user which method to use
1173+
- =false= - don't create a property; the user has to define it explicitly before attaching files
1174+
1175+
*** org_attach_method
1176+
:PROPERTIES:
1177+
:CUSTOM_ID: org_attach_method
1178+
:END:
1179+
- Type: ='cp'|'mv'|'ln'|'lns'=
1180+
- Default: ='cp'=
1181+
1182+
The preferred method to add files to the attachment directory.
1183+
1184+
- =mv= - move (rename) the file
1185+
- =cp= - copy the file
1186+
- =ln= - create a hard link; not supported on all systems
1187+
- =lns= - create a symbol link; not supported on all systems; on Windows, this always creates a /junction/
1188+
1189+
*** org_attach_copy_directory_create_symlink
1190+
:PROPERTIES:
1191+
:CUSTOM_ID: org_attach_copy_directory_create_symlink
1192+
:END:
1193+
- Type: =boolean=
1194+
- Default: =false=
1195+
1196+
If =true=, whenever the attachments directory itself is a symlink, and it
1197+
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
1198+
symlink itself. The default is to treat the symlink transparently as
1199+
a directory.
1200+
1201+
*** org_attach_use_inheritance
1202+
:PROPERTIES:
1203+
:CUSTOM_ID: org_attach_use_inheritance
1204+
:END:
1205+
- Type: ='always'|'selective'|'never'=
1206+
- Default: ='selective'=
1207+
1208+
Attachment inheritance for the outline.
1209+
1210+
Enabling inheritance implies that running =attach= inside a node without
1211+
attachments will operate on the first parent headline that has an
1212+
attachment.
1213+
1214+
Possible values are:
1215+
1216+
- =always= - inherit attachments
1217+
- =selective= - respect [[#org_use_property_inheritance][org_use_property_inheritance]] for the properties =DIR= and =ID=
1218+
- =never= - don't inherit attachments
1219+
1220+
*** org_attach_id_to_path_function_list
1221+
:PROPERTIES:
1222+
:CUSTOM_ID: org_attach_id_to_path_function_list
1223+
:END:
1224+
- Type: =(string | fun(id: string): (string|nil))[]=
1225+
- Default: ={ 'uuid_folder_format', 'ts_folder_format', 'fallback_folder_format' }=
1226+
1227+
List of functions that are tried sequentially to derive an attachment path
1228+
from an =ID= property. The functions are called with a single =id= argument
1229+
until the return value is an existing folder. The ID format passed to the
1230+
functions is usually defined by [[#org_id_method][org_id_method]].
1231+
1232+
If no folder has been created yet for the given ID, then the first truthy
1233+
value defines the path of the folder to be created.
1234+
1235+
The default functions avoid putting all attachment directories directly
1236+
inside [[#org_attach_id_dir][org_attach_id_dir]]. Some file systems have performance issues in
1237+
such scenarios.
1238+
1239+
Be careful when changing this setting. If you remove a function, previously
1240+
created attachment folders may be no longer mapped correctly and Org may be
1241+
unable to detect them.
1242+
11351243
** Mappings
11361244
:PROPERTIES:
11371245
:CUSTOM_ID: mappings
@@ -2049,6 +2157,13 @@ See [[#clocking][Clocking]] for more details.
20492157
- Mapped to: =<leader>obt=
20502158
Tangle current file. See [[#extract-source-code-tangle][Extract source code (tangle)]] for more details.
20512159

2160+
**** org_attach
2161+
:PROPERTIES:
2162+
:CUSTOM_ID: org_attach
2163+
:END:
2164+
- Mapped to: =<Leader>o<C-A>=
2165+
Open the attach dispatcher. See [[#attachments][Attachments]] for more details.
2166+
20522167
**** org_show_help
20532168
:PROPERTIES:
20542169
:CUSTOM_ID: org_show_help
@@ -2807,6 +2922,22 @@ Running [[#org_babel_tangle][org_babel_tangle]] will create file =~/org/my_tangl
28072922
=print('Headline 1')=
28082923
=#+end_src=
28092924

2925+
*** Attachments
2926+
:PROPERTIES:
2927+
:CUSTOM_ID: attachments
2928+
:END:
2929+
2930+
There is almost complete support for file attachments (Orgmode link:
2931+
[[https://orgmode.org/manual/Attachments.html][Attachments]]). You can use [[#org_attach][org_attach]] to open the dispatcher and attach
2932+
files to an "attachment node" (either a headline or an entire org
2933+
file).
2934+
2935+
Attaching a file puts it in a directory associated with the attachment node.
2936+
Based on [[#org_attach_preferred_new_method][org_attach_preferred_new_method]], this either uses the =ID= or
2937+
the =DIR= property. See also [[#org_attach_id_dir][org_attach_id_dir]],
2938+
[[#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
2939+
to further customize the attachments directory.
2940+
28102941
** User interface
28112942
:PROPERTIES:
28122943
:CUSTOM_ID: user-interface

0 commit comments

Comments
 (0)