Skip to content

Commit bbac7a7

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 eb61f39 commit bbac7a7

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

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

2207+
**** org_attach
2208+
:PROPERTIES:
2209+
:CUSTOM_ID: org_attach
2210+
:END:
2211+
- Mapped to: =<Leader>o<C-A>=
2212+
Open the attach dispatcher. See [[#attachments][Attachments]] for more details.
2213+
20992214
**** org_show_help
21002215
:PROPERTIES:
21012216
:CUSTOM_ID: org_show_help
@@ -2854,6 +2969,22 @@ Running [[#org_babel_tangle][org_babel_tangle]] will create file =~/org/my_tangl
28542969
=print('Headline 1')=
28552970
=#+end_src=
28562971

2972+
*** Attachments
2973+
:PROPERTIES:
2974+
:CUSTOM_ID: attachments
2975+
:END:
2976+
2977+
There is almost complete support for file attachments (Orgmode link:
2978+
[[https://orgmode.org/manual/Attachments.html][Attachments]]). You can use [[#org_attach][org_attach]] to open the dispatcher and attach
2979+
files to an "attachment node" (either a headline or an entire org
2980+
file).
2981+
2982+
Attaching a file puts it in a directory associated with the attachment node.
2983+
Based on [[#org_attach_preferred_new_method][org_attach_preferred_new_method]], this either uses the =ID= or
2984+
the =DIR= property. See also [[#org_attach_id_dir][org_attach_id_dir]],
2985+
[[#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
2986+
to further customize the attachments directory.
2987+
28572988
** User interface
28582989
:PROPERTIES:
28592990
:CUSTOM_ID: user-interface

0 commit comments

Comments
 (0)