-
Notifications
You must be signed in to change notification settings - Fork 1
/
protogg.el
115 lines (102 loc) · 4.04 KB
/
protogg.el
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
;;; protogg.el --- project.el function remapping -*- lexical-binding: t -*-
;;
;; Copyright (C) 2023 by Stephe Nehrbass
;;
;; Author: nehrbash
;;
;; Keywords: convenience, minibuffer, protogg
;; Version: 0.1
;; Homepage: https://github.com/nehrbash/protogg
;;
;; This file is NOT part of GNU Emacs.
;;
;;; Commentary:
;;
;; Protogg remaps the `project.el' functions to their non-project related functions while also providing a minibuffer
;; keybinding to switch between the two functions.
;;
;;; Code:
(require 'project)
(require 'delsel)
(defgroup protogg nil
"Remap \=project\= keys to their regular counterpart."
:group 'convenience
:group 'minibuffer
:link '(url-link :tag "GitHub" "https://github.com/nehrbash/protogg")
:link '(emacs-library-link :tag "Library Source" "protogg.el")
:prefix "protogg-")
(defcustom protogg-minibuffer-toggle-key "M-q"
"Keybinding for switching protogg functions in the minibuffer."
:type 'key-sequence
:group 'protogg)
(defvar protogg--toggle nil
"Holds the state of protogg toggle.")
(defvar protogg--use-upper t
"Holds the state of protogg function state.")
(defvar-keymap protogg-minibuffer-mode-map
:doc "keybindings for toggling between interactive functions."
protogg-minibuffer-toggle-key #'protogg-switch-minibuffer)
;;;###autoload
(defun protogg-switch-minibuffer ()
"Switch between the project based function and regular function."
(interactive)
;; toggle between using function1 and function2
(if protogg--use-upper
(setq protogg--use-upper nil)
(setq protogg--use-upper t))
(unless (project-current)
(user-error "Not in project"))
(setq protogg--toggle t)
(minibuffer-keyboard-quit))
(define-minor-mode protogg-minibuffer-mode
"Toggle between two interactive functions when they are active in the minibuffer."
:init-value nil
:group 'protogg
:global nil
:keymap protogg-minibuffer-mode-map)
(with-eval-after-load 'minibuffer
(add-hook 'minibuffer-setup-hook #'protogg-minibuffer-mode))
;;;###autoload
(defmacro protogg-define (function1 function2 newfunc)
"Create function NEWFUNC to toggle between FUNCTION1 and FUNCTION2.
It determines which one to call based on project state."
`(defun ,newfunc ()
(interactive)
;; if protogg--toggle is true in a recursive call.
(if protogg--toggle
(setq protogg--toggle nil)
;; if not in a recursive call we need to reset to always default to function1
(setq protogg--use-upper t))
(if (and (project-current) protogg--use-upper)
(condition-case nil
(call-interactively ,function1)
(quit
(if protogg--toggle
(,newfunc))))
(condition-case nil
(call-interactively ,function2)
(quit
(if protogg--toggle
(,newfunc)))))))
;;;###autoload (autoload 'protogg-async-shell-command "protogg")
(protogg-define 'project-async-shell-command 'async-shell-command protogg-async-shell-command)
;;;###autoload (autoload 'protogg-compile "protogg")
(protogg-define 'project-compile 'compile protogg-compile)
;;;###autoload (autoload 'protogg-dired "protogg")
(protogg-define 'project-dired 'dired protogg-dired)
;;;###autoload (autoload 'protogg-eshell "protogg")
(protogg-define 'project-eshell 'eshell protogg-eshell)
;;;###autoload (autoload 'protogg-find-dired "protogg")
(protogg-define 'project-find-dir 'find-dired protogg-find-dired)
;;;###autoload (autoload 'protogg-find-file "protogg")
(protogg-define 'project-find-file 'find-file protogg-find-file)
;;;###autoload (autoload 'protogg-list-buffers "protogg")
(protogg-define 'project-list-buffers 'list-buffers protogg-list-buffers)
;;;###autoload (autoload 'protogg-shell "protogg")
(protogg-define 'project-shell 'shell protogg-shell)
;;;###autoload (autoload 'protogg-shell-command "protogg")
(protogg-define 'project-shell-command 'shell-command protogg-shell-command)
;;;###autoload (autoload 'protogg-switch-to-buffer "protogg")
(protogg-define 'project-switch-to-buffer 'switch-to-buffer protogg-switch-to-buffer)
(provide 'protogg)
;;; protogg.el ends here