Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Define custom function to switch to a project. #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ To customize it and customize its icon;
:face 'font-lock-keyword-face))
#+END_SRC

To use it with [[https://github.com/ericdanan/counsel-projectile][counsel-projectile]] or [[https://github.com/bbatsov/persp-projectile][persp-projectile]]

#+begin_src elisp
(setq dashboard-projects-switch-function 'counsel-projectile-switch-project-by-name)
#+end_src

Or

#+begin_src elisp
(setq dashboard-projects-switch-function 'projectile-persp-switch-project)
#+end_src

** Org mode’s agenda

To display today’s agenda items on the dashboard, add ~agenda~ to ~dashboard-items~:
Expand Down
59 changes: 39 additions & 20 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
Expand Up @@ -669,39 +669,58 @@ WIDGET-PARAMS are passed to the \"widget-create\" function."
;;
;; Projects
;;
(defcustom dashboard-projects-switch-function
nil
"Custom function to switch to projects from dashboard."
:type 'function
:group 'dashboard)

(defun dashboard-insert-projects (list-size)
"Add the list of LIST-SIZE items of projects."
(dashboard-insert-section
"Projects:"
(dashboard-subseq (dashboard-projects-backend-load-projects) 0 list-size)
list-size
(dashboard-get-shortcut 'projects)
`(lambda (&rest ignore)
(funcall (dashboard-projects-backend-switch-function) ,el))
(abbreviate-file-name el)))

(defun dashboard-projects-backend-load-projects ()
"Depending on `dashboard-projects-backend' load corresponding backend.
Return function that returns a list of projects."
(cond
((eq dashboard-projects-backend 'projectile)
(require 'projectile)
(let ((inhibit-message t) (message-log-max nil))
(let ((inhibit-message t)
(message-log-max nil))
(projectile-cleanup-known-projects))
(projectile-load-known-projects)
(dashboard-insert-section
"Projects:"
(dashboard-subseq (projectile-relevant-known-projects)
0 list-size)
list-size
(dashboard-get-shortcut 'projects)
`(lambda (&rest ignore) (projectile-switch-project-by-name ,el))
(abbreviate-file-name el)))
(projectile-load-known-projects))
((eq dashboard-projects-backend 'project-el)
(require 'project)
(dashboard-insert-section
"Projects:"
(dashboard-subseq (project-known-project-roots) 0 list-size)
list-size
(dashboard-get-shortcut 'projects)
`(lambda (&rest ignore)
(let ((default-directory ,el)
(project-current-inhibit-prompt t))
(call-interactively 'project-find-file)))
(abbreviate-file-name el)))
(project-known-project-roots))
(t
(display-warning '(dashboard)
"Invalid value for `dashboard-projects-backend'"
:error))))

(defun dashboard-projects-backend-switch-function ()
"Return the function to switch to a project.
Custom variable `dashboard-projects-switch-function' variable takes preference
over custom backends."
(or dashboard-projects-switch-function
(cond
((eq dashboard-projects-backend 'projectile)
'projectile-switch-project-by-name)
((eq dashboard-projects-backend 'project-el)
(lambda (project)
"This function is used to switch to `PROJECT'."
(let ((default-directory project))
(project-find-file))))
(t
(display-warning '(dashboard)
"Invalid value for `dashboard-projects-backend'"
:error)))))
;;
;; Org Agenda
;;
Expand Down