@@ -10,53 +10,57 @@ local utils = require('telescope-orgmode.utils')
10
10
11
11
local api = require (' orgmode.api' )
12
12
13
- return function (opts )
14
- opts = opts or {}
13
+ local M = {}
15
14
16
- local closest_headline = api .current ():get_closest_headline ()
15
+ M .refile = function (prompt_bufnr )
16
+ local entry = action_state .get_selected_entry ()
17
+ actions .close (prompt_bufnr )
17
18
18
- local function refile (prompt_bufnr )
19
- local entry = action_state .get_selected_entry ()
20
- actions .close (prompt_bufnr )
19
+ -- Refile to the file by default
20
+ local destination = entry .value .file
21
21
22
- -- Refile to the file by default
23
- local destination = entry .value .file
22
+ -- Refile to a specific heading if is set
23
+ if entry .value .headline then
24
+ destination = entry .value .headline
25
+ end
24
26
25
- -- Refile to a specific heading if is set
26
- if entry .value .headline then
27
- destination = entry .value .headline
28
- end
27
+ return api .refile ({
28
+ source = M .closest_headline ,
29
+ destination = destination ,
30
+ })
31
+ end
29
32
30
- return api .refile ({
31
- source = closest_headline ,
32
- destination = destination ,
33
- })
33
+ M .gen_depth_toggle = function (opts , prompt_bufnr )
34
+ local status = state .get_status (prompt_bufnr )
35
+ status ._ot_current_depth = opts .max_depth
36
+ status ._ot_next_depth = nil
37
+ if status ._ot_current_depth ~= 0 then
38
+ status ._ot_next_depth = 0
34
39
end
35
40
36
- local function gen_depth_toggle (opts , prompt_bufnr )
37
- local status = state .get_status (prompt_bufnr )
38
- status ._ot_current_depth = opts .max_depth
39
- status ._ot_next_depth = nil
40
- if status ._ot_current_depth ~= 0 then
41
- status ._ot_next_depth = 0
42
- end
43
-
44
- return function ()
45
- local current_picker = action_state .get_current_picker (prompt_bufnr )
41
+ return function ()
42
+ local current_picker = action_state .get_current_picker (prompt_bufnr )
46
43
47
- local aux = status ._ot_current_depth
48
- status ._ot_current_depth = status ._ot_next_depth
49
- status ._ot_next_depth = aux
44
+ local aux = status ._ot_current_depth
45
+ status ._ot_current_depth = status ._ot_next_depth
46
+ status ._ot_next_depth = aux
50
47
51
- opts .max_depth = status ._ot_current_depth
52
- local new_finder = finders .new_table ({
53
- results = utils .get_entries (opts ),
54
- entry_maker = opts .entry_maker or utils .make_entry (opts ),
55
- })
48
+ opts .max_depth = status ._ot_current_depth
49
+ local new_finder = finders .new_table ({
50
+ results = utils .get_entries (opts ),
51
+ entry_maker = opts .entry_maker or utils .make_entry (opts ),
52
+ })
56
53
57
- current_picker :refresh (new_finder , opts )
58
- end
54
+ current_picker :refresh (new_finder , opts )
59
55
end
56
+ end
57
+
58
+ M .closest_headline = nil
59
+
60
+ return function (opts )
61
+ opts = opts or {}
62
+
63
+ M .closest_headline = api .current ():get_closest_headline ()
60
64
61
65
pickers
62
66
.new (opts , {
@@ -70,8 +74,8 @@ return function(opts)
70
74
sorter = conf .generic_sorter (opts ),
71
75
previewer = conf .grep_previewer (opts ),
72
76
attach_mappings = function (prompt_bufnr , map )
73
- action_set .select :replace (refile )
74
- map (' i' , ' <c-space>' , gen_depth_toggle (opts , prompt_bufnr ))
77
+ action_set .select :replace (M . refile )
78
+ map (' i' , ' <c-space>' , M . gen_depth_toggle (opts , prompt_bufnr ))
75
79
return true
76
80
end ,
77
81
})
0 commit comments