Skip to content

Commit b6dede8

Browse files
committed
docs: add type docs to entry function
1 parent 4978fb5 commit b6dede8

3 files changed

Lines changed: 51 additions & 52 deletions

File tree

lua/lib/actions/init.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
local has_telescope = pcall(require, "telescope")
2-
if not has_telescope then
3-
vim.notify("Telescope is not installed", vim.log.levels.ERROR)
4-
return M
5-
end
61
local actions = require("telescope.actions")
72
local actions_state = require("telescope.actions.state")
83
local toggleterm_ui = require("toggleterm.ui")
@@ -206,7 +201,7 @@ function M.toggle_term(prompt_bufnr, exit_on_action)
206201
util.refresh_picker(prompt_bufnr, term)
207202
end
208203

209-
--- Rename a terminal. If exit_on_action is true, focus it.
204+
--- Rename a terminal.
210205
--- @param prompt_bufnr number The buffer number of the telescope prompt.
211206
--- @param exit_on_action boolean Whether to exit the telescope buffer when the action executes.
212207
function M.rename_term(prompt_bufnr, exit_on_action)

lua/lib/telescope/init.lua

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
1-
local pickers, telescope_actions, conf
2-
if pcall(require, "telescope") then
3-
pickers = require("telescope.pickers")
4-
telescope_actions = require("telescope.actions")
5-
conf = require("telescope.config").values
6-
else
7-
error("Cannot find telescope!")
8-
end
9-
local status_ok, _ = pcall(require, "toggleterm")
10-
if not status_ok then
11-
error("Cannot find toggleterm!")
12-
end
1+
local pickers = require("telescope.pickers")
2+
local telescope_actions = require("telescope.actions")
3+
local conf = require("telescope.config").values
134
local util = require("util")
145

6+
--- Create autocommand to enter insert mode when the cursor leaves the telescope buffer.
7+
--- Useful for actions that are called with exit_on_action set to false b/c it allows the user
8+
--- to manually exit telescope but still automatically enter insert mode in the terminal buffer
9+
--- @param picker table The telescope picker object.
10+
local function telescope_leave_autocmd(picker)
11+
vim.api.nvim_create_augroup("InsertOnPickerLeave", {})
12+
vim.api.nvim_create_autocmd("BufLeave", {
13+
buffer = picker.prompt_bufnr,
14+
group = "InsertOnPickerLeave",
15+
nested = true,
16+
once = true,
17+
callback = function()
18+
local desktopPath = os.getenv("HOME") .. "/Desktop/new.txt"
19+
local file, err = io.open(desktopPath, "a")
20+
if not file then
21+
print("Error opening file:", err)
22+
return
23+
end
24+
file:write("leave" .. "\n")
25+
26+
local win_is_valid = vim.api.nvim_win_is_valid(picker.original_win_id)
27+
file:write("picker.original_win_id: " .. picker.original_win_id .. "\n")
28+
if win_is_valid then
29+
file:write("win_is_valid" .. "\n")
30+
local picker_orig_win_bufnr = vim.fn.winbufnr(picker.original_win_id)
31+
local buftype = vim.api.nvim_buf_get_option(picker_orig_win_bufnr, "filetype")
32+
file:write("buftype: " .. buftype .. "\n")
33+
if buftype == "toggleterm" then
34+
util.start_insert_mode()
35+
end
36+
end
37+
file:write("\n")
38+
file:close()
39+
end,
40+
})
41+
end
42+
1543
local M = {}
44+
45+
--- Entry point. Opens a telescope picker.
46+
--- @param opts table The options for the picker.
1647
M.open = function(opts)
1748
local config = require("config").options
1849
-- set origin window, which will need to be retrieved in some actions (actions/init.lua)
@@ -43,39 +74,6 @@ M.open = function(opts)
4374
end,
4475
})
4576
picker:find()
46-
47-
-- create autocommand to enter insert mode when the cursor leaves the telescope buffer
48-
-- useful for actions that are called with exit_on_action set to false b/c it allows the user
49-
-- to manually exit telescope but still automatically enter insert mode in the terminal buffer
50-
vim.api.nvim_create_augroup("InsertOnPickerLeave", {})
51-
vim.api.nvim_create_autocmd("BufLeave", {
52-
buffer = picker.prompt_bufnr,
53-
group = "InsertOnPickerLeave",
54-
nested = true,
55-
once = true,
56-
callback = function()
57-
local desktopPath = os.getenv("HOME") .. "/Desktop/new.txt"
58-
local file, err = io.open(desktopPath, "a")
59-
if not file then
60-
print("Error opening file:", err)
61-
return
62-
end
63-
file:write("leave" .. "\n")
64-
65-
local win_is_valid = vim.api.nvim_win_is_valid(picker.original_win_id)
66-
file:write("picker.original_win_id: " .. picker.original_win_id .. "\n")
67-
if win_is_valid then
68-
file:write("win_is_valid" .. "\n")
69-
local picker_orig_win_bufnr = vim.fn.winbufnr(picker.original_win_id)
70-
local buftype = vim.api.nvim_buf_get_option(picker_orig_win_bufnr, "filetype")
71-
file:write("buftype: " .. buftype .. "\n")
72-
if buftype == "toggleterm" then
73-
util.start_insert_mode()
74-
end
75-
end
76-
file:write("\n")
77-
file:close()
78-
end,
79-
})
77+
telescope_leave_autocmd(picker)
8078
end
8179
return M

lua/telescope-toggleterm.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
local has_telescope = pcall(require, "telescope")
2+
if not has_telescope then
3+
vim.notify("Telescope is not installed", vim.log.levels.ERROR)
4+
return
5+
end
6+
17
local M = {}
28
require("telescope").load_extension("toggleterm")
39

0 commit comments

Comments
 (0)