Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

make telescope <leader>. open dir of currently active file #94

Closed
molleweide opened this issue Aug 9, 2021 · 7 comments · Fixed by #160
Closed

make telescope <leader>. open dir of currently active file #94

molleweide opened this issue Aug 9, 2021 · 7 comments · Fixed by #160
Labels
hacktoberfest ready for contributors to work on scope: enhancement New feature or request

Comments

@molleweide
Copy link
Contributor

Does this make sense?

I think that it would be nice if telescope Browse Files would open the dir of currently active file and not the root dir where vim was started. I haven't had time to look into telescope configs yet. I'll close after I have time to test this.

@NTBBloodbath
Copy link
Collaborator

Hey, yeah it does for me. We will need to take a look at telescope source to look if there's an option for this or if we will need to do it from scratch. Hope there's an option so we'll be able to add this feature sooner :)

@NTBBloodbath NTBBloodbath added the scope: enhancement New feature or request label Aug 10, 2021
@molleweide
Copy link
Contributor Author

I am going to see if I can add telescope-z into doom also later for faster CWD switching

@osamuaoki
Copy link
Contributor

osamuaoki commented Sep 25, 2021

Telescope has this opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd() at the start.

So directory of current buffer: expand('%:p:h') Then set opts.cwd to it?

Maybe original opts.cwd needs to be retained?

@osamuaoki
Copy link
Contributor

I think I got a working prototype.

From be96b7f537e3b41c6341e0b9f5ce2c240e3c7bfe Mon Sep 17 00:00:00 2001
From: Osamu Aoki <[email protected]>
Date: Sun, 26 Sep 2021 03:21:25 +0900
Subject: [PATCH] find-files cwd

Signed-off-by: Osamu Aoki <[email protected]>
---
 lua/doom/core/functions/init.lua       | 18 ++++++++++++++++++
 lua/doom/extras/keybindings/leader.lua |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lua/doom/core/functions/init.lua b/lua/doom/core/functions/init.lua
index c8569c5..db3d073 100644
--- a/lua/doom/core/functions/init.lua
+++ b/lua/doom/core/functions/init.lua
@@ -561,4 +561,22 @@ M.toggle_spell = function()
   end
 end
 
+-- Ref: https://github.com/tjdevries/lazy.nvim
+local function require_on_exported_call(mod)
+  return setmetatable({}, {
+    __index = function(_, picker)
+      return function(...)
+        return require(mod)[picker](...)
+      end
+    end,
+  })
+end
+
+local opts = {}
+opts.cwd = vim.fn.expand("%:p:h")
+-- toggle_spell open current directory of current buffer file
+M.find_files = function()
+  require_on_exported_call("telescope.builtin.files").find_files(opts)
+end
+
 return M
diff --git a/lua/doom/extras/keybindings/leader.lua b/lua/doom/extras/keybindings/leader.lua
index 6f60a34..5bfa558 100644
--- a/lua/doom/extras/keybindings/leader.lua
+++ b/lua/doom/extras/keybindings/leader.lua
@@ -302,7 +302,8 @@ utils.map(
 utils.map(
   "n",
   "<leader>ff",
-  "<cmd>Telescope find_files<CR>",
+--  "<cmd>Telescope find_files<CR>",
+  '<cmd>lua require("doom.core.functions").find_files()<CR>',
   opts,
   "Editor",
   "find_files_alt",
-- 
2.33.0

@osamuaoki
Copy link
Contributor

If you are using main branch, files are a bit different. I think this helps.
43681ea

@osamuaoki
Copy link
Contributor

I think original behavior also have some value.

NTBBloodbath: How do you want this to be included? Replace <leader>ff or add another binding? I think latter may be more desirable. If you tell me the choices for keybinding and word to describe this, I think I can create PR.

@NTBBloodbath
Copy link
Collaborator

NTBBloodbath: How do you want this to be included? Replace <leader>ff or add another binding? I think latter may be more desirable. If you tell me the choices for keybinding and word to describe this, I think I can create PR.

Woops my bad, don't know how I did miss this. I think we could add a new keybind with a description like "Find files in current project", yeah this makes sense. Maybe under the <leader>f section too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hacktoberfest ready for contributors to work on scope: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants