summaryrefslogtreecommitdiff
path: root/modules/test-code.el
blob: 0dc9cbd76140150fcfeca9d9d8276d0da199261d (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
;;; test-code.el --- test code -*- lexical-binding: t; -*-
;; author: Craig Jennings <c@cjennings.net>

;;; Commentary:

;; This is where to put config code you're working on before it's tested and stable.
;; Include this at the very end of your init.el. This way, if something does break,
;; and it will, most of your Emacs config is loaded.

;; Once you've tested (and time-tested) the code here, graduate it into the proper
;; section of your config above.

;;; Code:

(require 'user-constants)

;; ------------------------------ Buffer Same Mode -----------------------------

(defun cj/buffer-same-mode (&rest modes)
  "Pop to a buffer with a mode among MODES, or the current one if not given."
  (interactive)
  (let* ((modes (or modes (list major-mode)))
         (pred (lambda (b)
                 (let ((b (get-buffer (if (consp b) (car b) b))))
                   (member (buffer-local-value 'major-mode b) modes)))))
    (pop-to-buffer (read-buffer "Buffer: " nil t pred))))
(global-set-key (kbd "C-x B") 'cj/buffer-same-mode)

;; --------------------------------- Org Noter ---------------------------------

(use-package org-noter
  :after (:any org pdf-view)
  :commands org-noter
  :bind ("<f6>" . org-noter)
  :config
  (setq org-noter-always-create-frame nil)
  (setq org-noter-notes-window-location 'vertical-split)
  (setq org-noter-notes-window-behavior 'scroll)
  (setq org-noter-doc-split-fraction '(0.75 . 0.75))
  (setq org-noter-notes-search-path (concat sync-dir "/org-noter/"))
  (setq org-noter-default-notes-file-names '("reading-notes.org"))
  (setq org-noter-separate-notes-from-heading t)
  (org-noter-enable-org-roam-integration))

(use-package org-pdftools
  :after (org pdf-view)
  :hook (org-mode . org-pdftools-setup-link))

;; --------------------------------- Easy Hugo ---------------------------------

(use-package easy-hugo
  :defer .5
  :init
  (setq easy-hugo-basedir "~/code/cjennings-net/")
  (setq easy-hugo-url "https://cjennings.net")
  (setq easy-hugo-sshdomain "cjennings.net")
  (setq easy-hugo-root "/var/www/cjennings/")
  (setq easy-hugo-previewtime "300")
  (setq easy-hugo-postdir "content")
  (setq easy-hugo-server-flags "-D --noHTTPCache --disableFastRender")
  (setq easy-hugo-default-ext ".md")
  :bind ("C-c H" . easy-hugo)
  :config
  (easy-hugo-enable-menu))

;; ------------------------------------ Pomm -----------------------------------

(use-package pomm
  :defer .5
  :bind ("M-p" . pomm)
  :commands (pomm pomm-third-time))

;; ------------------------ Org-Branch To Org-Roam-Node ------------------------

(defun cj/move-org-branch-to-roam ()
  (interactive)
  (when (eq (org-element-type (org-element-at-point)) 'headline)
    (let* ((headline-components (org-heading-components))
           (title (nth 4 headline-components)))
      (setq cj/point (point))
      (org-cut-subtree)
      ;; Switch to org-roam buffer, fill in new node's title.
      (org-roam-node-insert
       :immediate-finish t
       :no-edit t
       ;; Pass the current headline title as the default value.
       :region (cons (point)
                     (save-excursion
                       (insert title)
                       (point))))
      (newline)
      ;; Paste the 'cut' subtree and save buffer.
      (org-yank)
      (save-buffer)
      ;; Go back to the initial buffer and position.
      (switch-to-buffer (other-buffer))
      (goto-char cj/point)
      ;; Kill the org-roam link leftover.
      (kill-whole-line))))

;; ----------------------------------- Mpdel -----------------------------------

;; (use-package mpdel
;;   :defer .5
;;   :config
;;   (setq mpdel-prefix-key (kbd "M-p"))
;;   (mpdel-mode))

;; -------------------------------- Google This --------------------------------

;; not working as-is
;; (use-package google-this
;;   :load-path "~/code/emacs-google-this/"
;;   :defer 1
;;   :bind
;;   ("C-h g" . google-this-search)
;;   :config
;;   (google-this-mode 1)
;;   (setq google-this-browse-url-function 'eww-browse-url))

;; ------------------------------ Mouse Trap Mode ------------------------------

(defvar mouse-trap-mode-map
  (let* ((prefixes '("" "C-" "M-" "S-" "C-M-" "C-S-" "M-S-" "C-M-S-")) ; modifiers
         (buttons  (number-sequence 1 5))                             ; mouse-1..5
         (types    '("mouse" "down-mouse" "drag-mouse"
                     "double-mouse" "triple-mouse"))
         (wheel    '("wheel-up" "wheel-down" "wheel-left" "wheel-right"))
         (map (make-sparse-keymap)))
    ;; clicks, drags, double, triple
    (dolist (type types)
      (dolist (pref prefixes)
        (dolist (n buttons)
          (define-key map (kbd (format "<%s%s-%d>" pref type n)) #'ignore))))
    ;; wheel
    (dolist (evt wheel)
      (dolist (pref prefixes)
        (define-key map (kbd (format "<%s%s>" pref evt)) #'ignore)))
    map)
  "Keymap for `mouse-trap-mode'. Unbinds almost every mouse event.
Disabling mouse prevents accidental mouse moves modifying text.")

(define-minor-mode mouse-trap-mode
  "Globally disable most mouse and trackpad events.
When active, <mouse-*>, <down-mouse-*>, <drag-mouse-*>,
<double-mouse-*>, <triple-mouse-*>, and wheel events are bound to `ignore',
with or without C-, M-, S- modifiers."
  :global t
  :lighter " 🐭"
  :keymap mouse-trap-mode-map)
(global-set-key (kbd "C-c M") #'mouse-trap-mode)
(mouse-trap-mode 1)

(provide 'test-code)
;;; test-code.el ends here.