Skip to content

Commit df0bc7c

Browse files
authored
Merge pull request #2245 from VisenDev/init
Add `open-init-file` command
2 parents dedac80 + c83226d commit df0bc7c

5 files changed

Lines changed: 33 additions & 2 deletions

File tree

extensions/lem-dashboard/dashboard-items.lisp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,15 @@ Returns three values: prefix, main-text, suffix."
212212
(lambda ()
213213
(find-file f))))))
214214
(insert-character point #\Newline))))))))
215+
216+
(defclass dashboard-init-file (dashboard-item)
217+
()
218+
(:documentation "Lets the user open their init file.")
219+
(:default-initargs
220+
:item-attribute 'document-header4-attribute
221+
:action (lambda ()
222+
(lem:call-command 'lem-core/commands/file:open-init-file nil))))
223+
224+
(defmethod draw-dashboard-item ((item dashboard-init-file) point)
225+
(insert-string point (create-centered-string "Open Init File") :attribute 'document-header4-attribute)
226+
(insert-character point #\Newline))

extensions/lem-dashboard/default-dashboard.lisp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
:display-text " New Lisp Scratch Buffer (l)"
5858
:action-command 'lem-lisp-mode:lisp-scratch
5959
:item-attribute 'document-header2-attribute
60+
:bottom-margin 1)
61+
(make-instance 'dashboard-command
62+
:display-text "⚒ Open Lem Init File (i)"
63+
:action-command 'lem-core/commands/file:open-init-file
64+
:item-attribute 'document-header2-attribute
6065
:bottom-margin 2))))
6166
(unless hide-links
6267
(setf dashboard-items
@@ -82,5 +87,6 @@
8287
(define-key *dashboard-mode-keymap* "r" 'dashboard-move-to-recent-projects)
8388
(define-key *dashboard-mode-keymap* "f" 'dashboard-move-to-recent-files)
8489
(define-key *dashboard-mode-keymap* "l" 'lem-lisp-mode/internal:lisp-scratch)
90+
(define-key *dashboard-mode-keymap* "i" 'lem-core/commands/file:open-init-file)
8591

8692
(set-default-dashboard)

src/commands/file.lisp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:find-file-executor
55
:execute-find-file
66
:find-file
7+
:open-init-file
78
:find-file-recursively
89
:read-file
910
:add-newline-at-eof-on-writing-file
@@ -106,6 +107,10 @@
106107
(when (bufferp buffer)
107108
(switch-to-buffer buffer t nil))))))
108109

110+
(define-command open-init-file () ()
111+
"Opens the lem init file"
112+
(find-file (lem-core:get-preferred-init-file-path)))
113+
109114
(defmethod execute-find-file :before (executor mode pathname)
110115
(directory-for-file-or-lose pathname))
111116

src/internal-packages.lisp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@
638638
:init-at-build-time
639639
:lem
640640
:launch
641-
:main)
641+
:main
642+
:get-preferred-init-file-path)
642643
;; command-advices.lisp
643644
(:export
644645
:movable-advice

src/lem.lisp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
(defvar *in-the-editor* nil)
99

10+
(defparameter *init-file-name* "init.lisp"
11+
"The name of the init file found within (lem-home)")
12+
1013
(defun setup-first-frame ()
1114
(let ((frame (make-frame nil)))
1215
(map-frame (implementation) frame)
@@ -33,6 +36,10 @@
3336
(defun teardown ()
3437
(teardown-frames))
3538

39+
(defun get-preferred-init-file-path ()
40+
"Returns the full path to the preferred init file"
41+
(merge-pathnames *init-file-name* (lem-home)))
42+
3643
(defun load-init-file ()
3744
(flet ((maybe-load (path)
3845
(when (probe-file path)
@@ -42,7 +49,7 @@
4249
(let ((home (user-homedir-pathname))
4350
(current-dir (probe-file "."))
4451
(*package* (find-package :lem-user)))
45-
(or (maybe-load (merge-pathnames "init.lisp" (lem-home)))
52+
(or (maybe-load (get-preferred-init-file-path))
4653
(maybe-load (merge-pathnames ".lemrc" home)))
4754
(unless (uiop:pathname-equal current-dir (user-homedir-pathname))
4855
(maybe-load (merge-pathnames ".lemrc" current-dir))))))

0 commit comments

Comments
 (0)