Skip to content

Commit 43f74e2

Browse files
committed
feat(attach): add org-attach feature
1 parent 862d966 commit 43f74e2

File tree

13 files changed

+2883
-0
lines changed

13 files changed

+2883
-0
lines changed

docs/configuration.org

Lines changed: 210 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]]
@@ -1152,6 +1153,171 @@ Using the example above, setting this variable to ={'MYTAG'}=, second
11521153
and third headline would have only =CHILDTAG=, where =MYTAG= would not
11531154
be inherited.
11541155

1156+
** Attachments settings
1157+
:PROPERTIES:
1158+
:CUSTOM_ID: attachment-settings
1159+
:END:
1160+
1161+
*** org_attach_id_dir
1162+
:PROPERTIES:
1163+
:CUSTOM_ID: org_attach_id_dir
1164+
:END:
1165+
- Type: =string=
1166+
- Default: ='./data/'=
1167+
1168+
The directory where attachments are stored. If this is a relative path, it
1169+
will be interpreted relative to the directory where the Org file lives.
1170+
1171+
*** org_attach_dir_relative
1172+
:PROPERTIES:
1173+
:CUSTOM_ID: org_attach_dir_relative
1174+
:END:
1175+
- Type: =boolean=
1176+
- Default: =false=
1177+
1178+
If =true=, whenever you add a =DIR= property to a headline, it is added as
1179+
a relative path. The default is to only add absolute paths.
1180+
1181+
*** org_attach_auto_tag
1182+
:PROPERTIES:
1183+
:CUSTOM_ID: org_attach_auto_tag
1184+
:END:
1185+
- Type: =string=
1186+
- Default: ='ATTACH'=
1187+
1188+
Tag that is added automatically when attaching files to a headline.
1189+
1190+
*** org_attach_preferred_new_method
1191+
:PROPERTIES:
1192+
:CUSTOM_ID: org_attach_preferred_new_method
1193+
:END:
1194+
- Type: ='id'|'dir'|'ask'|false=
1195+
- Default: ='id'=
1196+
1197+
This setting is used when attaching files to nodes that have neither an
1198+
=ID= nor a =DIR= property.
1199+
1200+
- =id= - create and use an =ID= property
1201+
- =dir= - create and use a =DIR= property
1202+
- =ask= - ask the user which method to use
1203+
- =false= - don't create a property; the user has to define it explicitly before attaching files
1204+
1205+
*** org_attach_method
1206+
:PROPERTIES:
1207+
:CUSTOM_ID: org_attach_method
1208+
:END:
1209+
- Type: ='cp'|'mv'|'ln'|'lns'=
1210+
- Default: ='cp'=
1211+
1212+
The preferred method to add files to the attachment directory.
1213+
1214+
- =mv= - move (rename) the file
1215+
- =cp= - copy the file
1216+
- =ln= - create a hard link; not supported on all systems
1217+
- =lns= - create a symbol link; not supported on all systems; on Windows, this always creates a /junction/
1218+
1219+
*** org_attach_copy_directory_create_symlink
1220+
:PROPERTIES:
1221+
:CUSTOM_ID: org_attach_copy_directory_create_symlink
1222+
:END:
1223+
- Type: =boolean=
1224+
- Default: =false=
1225+
1226+
If =true=, whenever the attachments directory itself is a symlink, and it
1227+
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
1228+
symlink itself. The default is to treat the symlink transparently as
1229+
a directory.
1230+
1231+
*** org_attach_visit_command
1232+
:PROPERTIES:
1233+
:CUSTOM_ID: org_attach_visit_command
1234+
:END:
1235+
- Type: =string|fun(path: string)=
1236+
- Default: ='edit'=
1237+
1238+
Command or function used to open a directory. The default opens NetRW if it
1239+
is available.
1240+
1241+
*** org_attach_use_inheritance
1242+
:PROPERTIES:
1243+
:CUSTOM_ID: org_attach_use_inheritance
1244+
:END:
1245+
- Type: ='always'|'selective'|'never'=
1246+
- Default: ='selective'=
1247+
1248+
Attachment inheritance for the outline.
1249+
1250+
Enabling inheritance implies two things:
1251+
1. Attachment links will look through all parent headlines until they find
1252+
the linked attachment.
1253+
2. Running =attach= inside a node without attachments will operate on the
1254+
first parent headline that has an attachment.
1255+
1256+
Possible values are:
1257+
1258+
- =always= - inherit attachments
1259+
- =selective= - respect [[#org_use_property_inheritance][org_use_property_inheritance]] for the properties =DIR= and =ID=
1260+
- =never= - don't inherit attachments
1261+
1262+
*** org_attach_store_link_p
1263+
:PROPERTIES:
1264+
:CUSTOM_ID: org_attach_store_link_p
1265+
:END:
1266+
- Type: ='attached' | 'file' | 'original' | false=
1267+
- Default: ='attached'=
1268+
1269+
If not =false=, store a link with [[#org_store_link][org_store_link]] when attaching a file.
1270+
1271+
- =attach= - store a =[[attachment:name]]= link
1272+
- =file= - store a =[[file:attach_dir/name]]= link
1273+
- =original= - store a =[[file:original/location]]= link
1274+
1275+
*** org_attach_archive_delete
1276+
:PROPERTIES:
1277+
:CUSTOM_ID: org_attach_archive_delete
1278+
:END:
1279+
- Type: ='always' | 'ask' | 'never'=
1280+
- Default: ='never'=
1281+
1282+
Determines whether attachments are deleted automatically whenever a subtree
1283+
is moved to an archive file. The value ='ask'= means to ask the user.
1284+
1285+
*** org_attach_id_to_path_function_list
1286+
:PROPERTIES:
1287+
:CUSTOM_ID: org_attach_id_to_path_function_list
1288+
:END:
1289+
- Type: =(string | fun(id: string): (string|nil))[]=
1290+
- Default: ={ 'uuid_folder_format', 'ts_folder_format', 'fallback_folder_format' }=
1291+
1292+
List of functions that are tried sequentially to derive an attachment path
1293+
from an =ID= property. The functions are called with a single =id= argument
1294+
until the return value is an existing folder. The ID format passed to the
1295+
functions is usually defined by [[#org_id_method][org_id_method]].
1296+
1297+
If no folder has been created yet for the given ID, then the first truthy
1298+
value defines the path of the folder to be created.
1299+
1300+
The default functions avoid putting all attachment directories directly
1301+
inside [[#org_attach_id_dir][org_attach_id_dir]]. Some file systems have performance issues in
1302+
such scenarios.
1303+
1304+
Be careful when changing this setting. If you remove a function, previously
1305+
created attachment folders may be no longer mapped correctly and Org may be
1306+
unable to detect them.
1307+
1308+
*** org_attach_sync_delete_empty_dir
1309+
:PROPERTIES:
1310+
:CUSTOM_ID: org_attach_sync_delete_empty_dir
1311+
:END:
1312+
- Type: ='always'|'ask'|'never'=
1313+
- Default: ='ask'=
1314+
1315+
Determines whether to delete empty directories during [[https://orgmode.org/manual/Attachment-defaults-and-dispatcher.html*index-C_002dc-C_002da-z][org_attach_sync]].
1316+
1317+
- =never= - never delete empty directories
1318+
- =ask= - ask the user whether to delete
1319+
- =always= - delete empty directories without asking
1320+
11551321
** Mappings
11561322
:PROPERTIES:
11571323
:CUSTOM_ID: mappings
@@ -2062,6 +2228,13 @@ See [[#clocking][Clocking]] for more details.
20622228
- Mapped to: =<leader>obt=
20632229
Tangle current file. See [[#extract-source-code-tangle][Extract source code (tangle)]] for more details.
20642230

2231+
**** org_attach
2232+
:PROPERTIES:
2233+
:CUSTOM_ID: org_attach
2234+
:END:
2235+
- Mapped to: =<Leader>o<C-A>=
2236+
Open the attach dispatcher. See [[#attachments][Attachments]] for more details.
2237+
20652238
**** org_show_help
20662239
:PROPERTIES:
20672240
:CUSTOM_ID: org_show_help
@@ -2820,6 +2993,43 @@ Running [[#org_babel_tangle][org_babel_tangle]] will create file =~/org/my_tangl
28202993
=print('Headline 1')=
28212994
=#+end_src=
28222995

2996+
*** Attachments
2997+
:PROPERTIES:
2998+
:CUSTOM_ID: attachments
2999+
:END:
3000+
3001+
There is almost complete support for file attachments (Orgmode link:
3002+
[[https://orgmode.org/manual/Attachments.html][Attachments]]). You can use [[#org_attach][org_attach]] to open the dispatcher and attach
3003+
files to an "attachment node" (either a headline or an entire org
3004+
file).
3005+
3006+
Attaching a file puts it in a directory associated with the attachment node.
3007+
Based on [[#org_attach_preferred_new_method][org_attach_preferred_new_method]], this either uses the =ID= or
3008+
the =DIR= property. See also [[#org_attach_id_dir][org_attach_id_dir]],
3009+
[[#org_attach_dir_relative][org_attach_dir_relative]], [[#org_attach_id_to_path_function_list][org_attach_id_to_path_function_list]] and
3010+
[[#org_attach_use_inheritance][org_attach_use_inheritance]] on how to further customize the attachments
3011+
directory.
3012+
3013+
Attachment links are supported. A link like =[[attachment:file.txt]]=
3014+
looks up =file.txt= in the current node's attachments directory and opens
3015+
it. Attaching a file stores a link to the attachment. See
3016+
[[#org_attach_store_link_p][org_attach_store_link_p]] on how to configure this behavior.
3017+
3018+
You can also attach files from a different buffer. The following
3019+
mapping attaches the path under the cursor to the current headline of the
3020+
most recently open org file:
3021+
3022+
#+begin_src lua
3023+
vim.keymap.set('n', '<Leader>o+', function()
3024+
local file = vim.fn.expand('<cfile>')
3025+
local org = require('orgmode')
3026+
org.attach:attach_to_other_buffer(file)
3027+
end)
3028+
#+end_src
3029+
3030+
The only missing feature is expansion of attachment links before exporting
3031+
a file with [[#org_export][org_exporting]].
3032+
28233033
** User interface
28243034
:PROPERTIES:
28253035
:CUSTOM_ID: user-interface

0 commit comments

Comments
 (0)