Comments (6)
Maybe this code can help:
(defun my-deft-cd ()
"Run Deft in selected directory.
Prompt the user for a directory and run Deft in it."
(interactive)
(let ((deft-directory (expand-file-name (read-directory-name "Deft directory: "))))
(if (get-buffer deft-buffer)
(and (switch-to-buffer deft-buffer) (deft-refresh))
(deft))))
from deft.
I was also hoping for something similar. I would like to set the deft-directory per project using .dir-locals.el. However, it seems somehow the value of this variable can not be changed by .dir-locals.el and always remains as the value set during init. Is there any way to achieve this?
from deft.
As far as I recall, it is possible to change it during runtime with a simple setq
. Make sure to hit deft-refresh
after changing.
As for setting it as a local variable, I'm not sure how that would work.
from deft.
@hubgitname - Sorry for commenting on an old issue, but I stumbled upon this issue while I was looking for a solution. I threw together something real fast to make this work. It'll require projectile to work. Note it'll only work on a repo project. It also relies on a doom-emacs function to get your project-root directory which I provided below.
What this does is change your deft-directory to the projectile-project root directory and refreshes the deft directory when you switch projects.
(defun doom-project-root (&optional dir)
"Return the project root of DIR (defaults to `default-directory').
Returns nil if not in a project."
(let ((projectile-project-root (unless dir projectile-project-root))
projectile-require-project-root)
(projectile-project-root dir)))
Then add this function that'll set your deft-directory to your current project-root
(defun zyro/projectile-update-deft-directory ()
"Checks if directory is projectile-project and updates DEFT directory to the projects root folder."
(interactive)
(if (projectile-project-p)
(setq deft-directory (expand-file-name (doom-project-root)))))
Finally add these 2 hooks to projectile-after-switch-project-hook
so it updates the directory and refreshes deft.
(add-hook 'projectile-after-switch-project-hook 'zyro/projectile-update-deft-directory)
(add-hook 'projectile-after-switch-project-hook 'deft-refresh)
from deft.
Maybe this code can help:
(defun my-deft-cd () "Run Deft in selected directory. Prompt the user for a directory and run Deft in it." (interactive) (let ((deft-directory (expand-file-name (read-directory-name "Deft directory: ")))) (if (get-buffer deft-buffer) (and (switch-to-buffer deft-buffer) (deft-refresh)) (deft))))
This partially works. It opens the directory just right, but if you create a new fie either RET or C-RET, the file is created in the defined "root" directory, in my case .notes/, and not in the current directory.
E.g.
Create a new directory under .notes/ (mkdir foo)
Open Deft, it shows .notes files (default directory).
C-x C-g to run my-deft-cd and change directory to .notes/foo/
.
The new directory is empty.
Create new deft file.
Write something. ~ autosave, etc
cd
inside .notes/foo and ls
, the directory will be empty, the new file was created inside .notes/.
In the next days I will try to solve this, as I also think that this could be a very nice improvement for organization.
It's probably the case to setq the current directory in the correct variable as using let might not be enough (I'm new to Lisp so maybe I'm wrong).
Maybe it's the case to create a temp variable to setq the default directory into it, setq the find directory and when Deft or Emacs closes, setq back the default directory before exit.
from deft.
This will offer a solution on top of @saf-dmitry code.
(with-eval-after-load "deft"
(and
;; Save temp variable to recover configurations later.
(setq deft-default-directory deft-directory)
(defun deft-change-directory ()
"Run Deft in selected directory from prompt.
If directory doesn't exists, create."
(interactive)
(setq deft-directory (expand-file-name (read-directory-name "Deft directory: ")))
(unless (file-directory-p deft-directory)
(make-directory deft-directory t))
(if (get-buffer deft-buffer)
(and (switch-to-buffer deft-buffer) (deft-refresh))
(deft)))
(defun restore-deft ()
"When Deft buffer is killed, recover default deft-directory."
(interactive)
(if (string= (buffer-name) deft-buffer)
(setq deft-directory deft-default-directory)
nil)))
(add-hook 'kill-buffer-hook 'restore-deft)
(global-set-key (kbd "C-x C-g") 'deft-change-directory))
If you put (setq deft-default-directory deft-directory)
inside the deft-change-directory
function it will not have a desirable behavior (IMO), I.e. everytime you would close Deft, and open it again, Deft would be in the last visited directory instead on the configured default one.
deft-default-directory
will act as a temp variable for the original deft-directory
.
deft-change-directory
will prompt you to enter a directory by pressing C-x C-g
. If the desired directory doesn't exists it will create one just like on find-file. (maybe it would be best to prompt if you want it to be created)
restore-deft
will reset the deft-directory
for the default path when you kill the Deft buffer.
So you can have something like:
.deft/ ;; for general notes
.deft/book1 ;; specific notes
.deft/book2 ...
Of course Deft is pretty much organized already with it's killer search engine. But sometimes you might want a better organization for different projects and it will solve it just right. Now I'm one step closer to completly migrate from Scrivener to Emacs.
Although it's a good solution for our use case, this might not be a functionality for Deft as the author @jrblevin conceived it, so I will not offer a Pull Request without permission.
But if it solves your problem @hubgitname , you can mark as Solved or let me know if I can improve it.
Edit: Everything is inside eval-after-load
because I noticed that some deft variables would not be already bound and would rise an error on a new Emacs instance.
from deft.
Related Issues (20)
- Deft hangs on emacs 28 HOT 12
- Right to left text in file causes wrong alignment of date and time stamp in Deft file browser.
- Second search can not jump to accurate position
- Support custom filters? HOT 1
- How to make the title and content not on the same line๏ผ HOT 2
- How to make deft work with files without file extension?
- docu for `deft-file-naming-rules` missing HOT 1
- How to use `deft-file-naming-rules` with `usepackage` HOT 1
- Display file at point when using deft-find-file HOT 1
- Adding optional Xapian support HOT 12
- Incongruity between default file type and default summary generation
- Super slow
- Fix to make deft faster (also on older emacsen) HOT 3
- deft-file-mtime: Wrong type argument
- Default directory for new files
- message Package cl is deprecated HOT 1
- Emoji in org-mode files causing Deft summary lines to bleed over into next line
- Org-rifle vs deft HOT 1
- creating new files with Deft using prompt for title HOT 4
- deft-find-file: how to disable defaulting to "find-file" and instead use deft-new-file-format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deft.