summaryrefslogtreecommitdiff
path: root/elchemy-personal.el
blob: 8d13bdddf257ba633fcf04f40250f1cb3708fb9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
;; Ignore bell
(setq ring-bell-function 'ignore)

(setq python-shell-interpreter "~/.micromamba/envs/emacs-py/bin/ipython"
      python-shell-interpreter-args "--pylab")

(defun elchemy/add-to-pypath (&optional path)
  "# Add to python path"
  (interactive)
  (let* ((fullpath (if path
		       path
		     (ido-read-directory-name "Path: "))))
    (setenv "PYTHONPATH"
	    (let ((current (getenv "PYTHONPATH"))
		  (new fullpath))
	      (if current
		  (concat new ":" current)
		new)))))

(add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode))

(require 'eglot)
(define-key eglot-mode-map (kbd "C-c l r") 'eglot-rename)
(define-key eglot-mode-map (kbd "C-c l f") 'eglot-format)
(define-key eglot-mode-map (kbd "C-c l d") 'eldoc)

(setq org-format-latex-options (plist-put org-format-latex-options :scale 1.8))
(let ((png (cdr (assoc 'dvipng org-preview-latex-process-alist))))
  (plist-put png :latex-compiler '("latex -interaction nonstopmode -output-directory %o %F"))
  (plist-put png :image-converter '("dvipng -D %D -T tight -o %O %F"))
  (plist-put png :transparent-image-converter '("dvipng -D %D -T tight -bg Transparent -o %O %F")))

(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)
   (gnuplot . t)
   (R . t)))
(setq org-babel-python-command python-shell-interpreter)
(setq org-babel-R-command "/usr/local/bin/R --slave --no-save")
(setq org-babel-gnuplot-command "/usr/local/bin/gnuplot")
(setq org-confirm-babel-evaluate nil)

(defun elchemy/personal/ignore-angle-brackets ()
  "Ignore angle brackets in org mode"
  (modify-syntax-entry ?< ".")
  (modify-syntax-entry ?> "."))
(add-hook 'org-mode-hook 'elchemy/personal/ignore-angle-brackets)

(add-to-list 'load-path "~/.emacs.d/extras/")
(when (require 'writegood-mode nil t)
  (global-set-key (kbd "C-c g") 'writegood-mode))

(with-eval-after-load 'python
  (defun python-shell-completion-native-try ()
    "Return non-nil if can trigger native completion."
    (let ((python-shell-completion-native-enable t)
          (python-shell-completion-native-output-timeout
           python-shell-completion-native-try-output-timeout))
      (python-shell-completion-native-get-completions
       (get-buffer-process (current-buffer))
       nil "_"))))

(setq sentence-end-double-space nil)

(defun elchemy/read-alist-file (file-path)
  "Read a file where each line is an alist of the form (name . location), returning a list of these pairs."
  (interactive "fEnter file path: ")
  (let (result)
    (with-temp-buffer
      (insert-file-contents file-path)
      (goto-char (point-min))
      (while (not (eobp))
        (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
          (when (not (string-blank-p line))
            (let ((pair (car (read-from-string line))))
              (push pair result))))
        (forward-line 1)))
    (reverse result)))

(defun elchemy/find-file (FILENAME)
  "Find File to new split"
  (let ((buffer (find-file-noselect FILENAME)))
    (when (one-window-p)
      (split-window-right))
    (other-window 1)
    (switch-to-buffer buffer)))

(defun elchemy/term (TERM)
  "Terminal to new split"
  (when (one-window-p)
    (split-window-right))
  (other-window 1)
  (term TERM))

(defun elchemy/create-dashboard ()
  "Create the user dashboard"
  (interactive)
  (let ((buffer (get-buffer-create "*Dashboard*")))
    (switch-to-buffer buffer)
    (unless buffer-read-only
      (when (file-exists-p "~/.elchemy/assets/splash.png")
	(insert-image (create-image "~/.elchemy/assets/splash.png" nil nil :scale 0.25))
	(insert "\n"))
      (let ((start (point)))
	(insert "Elchemy Dashboard")
	(add-text-properties start (point)
			     '(face (:height 4.0))))
      (insert "\n\n")
      (insert
       (buttonize "Open Local TODO" (lambda (x) (elchemy/find-file "~/org/todo.org"))))
      (insert "    ")
      (insert
       (buttonize "Open Remote TODO" (lambda (x) (elchemy/find-file "/ssh:onid:todo.org"))))
      (insert "\n")
      (insert
       (buttonize "Open Local Notes" (lambda (x) (elchemy/find-file "~/org/notes.org"))))
      (insert "   ")
      (insert
       (buttonize "Open Remote Notes" (lambda (x) (elchemy/find-file "/ssh:onid:knowledge.org"))))
      (insert "\n\n")
      (insert
       (buttonize "Open Terminal (zsh)" (lambda (x) (elchemy/term "/bin/zsh"))))
      (insert "\n\n")
      (insert
       (buttonize "Open Personal Configuration" (lambda (x) (elchemy/find-file "~/.elchemy/elchemy-personal.el"))))
      (insert "\n\n")
      (when (file-exists-p "~/.elchemy/projects")
	(let ((start (point)))
	  (insert "Projects")
	  (add-text-properties start (point)
			       '(face (:height 1.5))))
	(insert "\n")
	(mapcar #'(lambda (x) (let ((name (car x))
			       (path (cdr x)))
			   (insert (buttonize name (lambda (y) (elchemy/find-file y)) path) "\n")))
		(elchemy/read-alist-file "~/.elchemy/projects"))
        (insert "\n"))
      (let ((start (point)))
	(insert "Command Reference")
	(add-text-properties start (point)
			     '(face (:height 1.5))))
      (insert "\n")
      (insert "C-/       ~ Undo\n")
      (insert "C-x n n   ~ Narrow\n")
      (insert "C-x n w   ~ Widen\n")
      (insert "M-%       ~ Query Replace\n")
      (insert "C-M-s     ~ Regex Search\n")
      (insert "F3        ~ Record Macro\n")
      (insert "F4        ~ Play Macro\n")
      (insert "M-0 F4    ~ Play Macro until failure\n")
      (insert "M-l       ~ Locwercase following word\n")
      (insert "M-u       ~ Uppercase following word\n")
      (insert "M-c       ~ Capitalize following word\n")
      (insert "M-g w     ~ Jump to word\n")
      (insert "M-g l     ~ Jump to line\n")
      (insert "C-x C-l   ~ Lowercase Region\n")
      (insert "C-x C-u   ~ Uppercase Region\n")
      (insert "C-M-n     ~ Move forward one balanced expression\n")
      (insert "C-M-p     ~ Move forward one balanced expression\n")
      (setq header-line-format nil)
      (read-only-mode +1))))
(elchemy/create-dashboard)

(add-to-list 'org-agenda-files "/ssh:onid:todo.org")
(add-to-list 'org-capture-templates '("o" "OSU Todo" entry (file+headline "/ssh:onid:todo.org" "Imported")
				      "* TODO %?\n  %i\n  %a\n"))
(add-to-list 'org-capture-templates '("k" "Knowledge Entry" entry (file+headline "/ssh:onid:knowledge.org" "Imported")
				      "* %?\n  %i\n  %a\n"))

(add-hook 'minibuffer-setup-hook
          (lambda ()
            (make-local-variable 'face-remapping-alist)
            (add-to-list 'face-remapping-alist '(default (:background "gray90")))))

(setq-default header-line-format '(
			 (:propertize "♥︎" face (:foreground "red"))
			 " "
			 (:propertize "ELCHEMY" face (:weight bold))
			 " "
			 (:propertize "♦︎" face (:foreground "red"))
			 " "
			 (:propertize "%b" face (:slant italic))
			 " ♣︎ "
			 (:eval mode-name)
			 " ♠︎"))

(load "extras/guile-interaction.el")
(require 'guile-interaction)

(provide 'elchemy-personal)