aboutsummaryrefslogtreecommitdiff
path: root/eb.el
diff options
context:
space:
mode:
Diffstat (limited to 'eb.el')
-rw-r--r--eb.el228
1 files changed, 141 insertions, 87 deletions
diff --git a/eb.el b/eb.el
index 14d6aed..b3691b1 100644
--- a/eb.el
+++ b/eb.el
@@ -4,6 +4,81 @@
;;; Code:
+;;;###autoload
+(defun eb-quit-or-bury ()
+ "Quit window or bury buffer."
+ (interactive)
+ (if (window-parameter (selected-window) 'quit-restore)
+ (quit-window)
+ (bury-buffer)))
+
+;;;###autoload
+(defun eb-exhume-buffer ()
+ "Switch to last buffer in the buffer list."
+ (interactive)
+ (switch-to-buffer (last-buffer)))
+
+;;;###autoload
+(defun eb-list-buffers (&optional arg all)
+ "List project buffers. By default, only file buffers are shown."
+ (interactive "P")
+ (require 'projectile)
+ (if eb--list-buffers
+ (quit-window)
+ (let ((buffer
+ (list-buffers-noselect (not arg)
+ (when (and (not all) (projectile-project-p))
+ (if arg
+ (projectile-project-buffers)
+ (mapcan
+ (lambda (b) (and (buffer-file-name b) (list b)))
+ (projectile-project-buffers)))))))
+ (display-buffer-in-direction buffer '((direction . up)))
+ (select-window (get-buffer-window buffer))
+ (with-current-buffer buffer
+ (setq-local eb--list-buffers t)))))
+
+;;;###autoload
+(defun eb-list-buffers-all (&optional arg)
+ "List all buffers. By default, only file buffers are shown."
+ (interactive "P")
+ (eb-list-buffers nil t))
+
+(define-advice Buffer-menu-mouse-select (:around (f event) eb-list-buffers)
+ (if eb--list-buffers
+ (progn
+ (select-window (posn-window (event-end event)))
+ (let ((buffer (tabulated-list-get-id (posn-point (event-end event)))))
+ (display-buffer buffer t)
+ (quit-window)))
+ (funcall f event)))
+
+;;;###autoload
+(defun eb-dired (&optional dir)
+ "Open the root of the current project in `dired'."
+ (interactive)
+ (require 'projectile)
+ (when eb--list-buffers (quit-window))
+ (setq dir (or dir (projectile-project-root)))
+ (if (and (eq major-mode 'dired-mode) (equal default-directory dir))
+ (bury-buffer)
+ (dired dir)))
+
+;;;###autoload
+(defun eb-dired-here ()
+ "Open the current working directory in `dired'."
+ (interactive)
+ (eb-dired default-directory))
+
+;;;###autoload
+(defun eb-grep ()
+ "Grep project."
+ (interactive)
+ (require 'projectile)
+ (if (projectile-project-p)
+ (call-interactively #'projectile-grep)
+ (call-interactively #'grep)))
+
(defcustom eb-system "vs2019"
"Build system (mingw/vs2019)."
:group 'eb
@@ -18,9 +93,9 @@
(defun eb-run ()
"Launch built executable, displaying its output in a buffer."
(interactive)
- (require 'project)
+ (require 'projectile)
(let ((buf (get-buffer-create "*eb-run*"))
- (exe (concat (project-root (project-current))
+ (exe (concat (projectile-project-root)
"/b/"
eb-system
(if (not (string-equal eb-system "mingw")) "/Debug/" "")
@@ -29,56 +104,39 @@
(with-current-buffer buf
(compilation-mode))
(start-process "EpisodeBrowser" buf exe)
+ (when (and (eq major-mode 'compilation-mode)
+ (window-parameter (selected-window) 'quit-restore))
+ (quit-window))
(display-buffer buf)))
+(defvar-local eb--list-buffers nil)
+
;;;###autoload
(defun eb-compile ()
"Compile without prompt."
(interactive)
(require 'projectile)
- (let ((compilation-read-command nil))
- (call-interactively #'projectile-compile-project)))
-
-(defvar-local eb--list-buffers nil)
+ (when (and (eq major-mode 'compilation-mode)
+ (window-parameter (selected-window) 'quit-restore))
+ (quit-window))
+ (if (projectile-project-p)
+ (let ((compilation-read-command nil))
+ (call-interactively #'projectile-compile-project))
+ (call-interactively #'compile)))
;;;###autoload
-(defun eb-list-buffers (&optional arg)
- "List project buffers."
- (interactive "P")
- (require 'projectile)
- (if eb--list-buffers
- (quit-window)
- (let ((buffer
- (list-buffers-noselect (not arg)
- (if arg
- (projectile-project-buffers)
- (mapcan
- (lambda (b) (and (buffer-file-name b) (list b)))
- (projectile-project-buffers))))))
- (display-buffer-in-direction buffer '((direction . up)))
- (select-window (get-buffer-window buffer))
- (with-current-buffer buffer
- (setq-local eb--list-buffers t)))))
-
-(define-advice Buffer-menu-mouse-select (:around (f event) eb-list-buffers)
- (if eb--list-buffers
- (progn
- (select-window (posn-window (event-end event)))
- (let ((buffer (tabulated-list-get-id (posn-point (event-end event)))))
- (display-buffer buffer t)
- (quit-window)))
- (funcall f event)))
-
-;;;###autoload
-(defun eb-dired ()
- "Open the root of the current project with `dired'."
+(defun eb-check ()
+ "Toggle `flycheck-list-errors'."
(interactive)
- (require 'project)
- (when eb--list-buffers (quit-window))
- (let ((project-root (project-root (project-current))))
- (if (and (eq major-mode 'dired-mode) (equal default-directory project-root))
- (bury-buffer)
- (dired project-root))))
+ (require 'flycheck)
+ (catch 'found
+ (dolist (win (window-list))
+ (with-selected-window win
+ (when (eq major-mode 'flycheck-error-list-mode)
+ (bury-buffer (window-buffer win))
+ (delete-window win)
+ (throw 'found t))))
+ (funcall #'flycheck-list-errors)))
;;;###autoload
(defun eb-vc ()
@@ -86,15 +144,7 @@
(interactive)
(require 'projectile)
(when eb--list-buffers (quit-window))
- (call-interactively #'projectile-vc))
-
-;;;###autoload
-(defun eb-quit-or-bury ()
- "Quit window or bury buffer."
- (interactive)
- (if (window-parameter (selected-window) 'quit-restore)
- (quit-window)
- (bury-buffer)))
+ (projectile-vc (or (projectile-project-root) default-directory)))
(defvar-local eb-tool-bar-mode--old-map nil)
(defvar-local eb-tool-bar-mode--old-back-button-mode nil)
@@ -103,61 +153,65 @@
;;;###autoload
(define-minor-mode eb-tool-bar-mode
"Useful tool bar buttons."
- nil " EB" nil
+ :lighter " EB"
(if eb-tool-bar-mode
(progn
- (require 'back-button)
(setq eb-tool-bar-mode--old-map tool-bar-map)
- (setq eb-tool-bar-mode--old-back-button-mode back-button-mode)
- (setq eb-tool-bar-mode--old-back-button-show-toolbar-buttons back-button-show-toolbar-buttons)
- (back-button-mode 1)
- (setq-local back-button-show-toolbar-buttons nil)
+ (when (require 'back-button nil t)
+ (setq eb-tool-bar-mode--old-back-button-mode back-button-mode)
+ (setq eb-tool-bar-mode--old-back-button-show-toolbar-buttons back-button-show-toolbar-buttons)
+ (back-button-mode 1)
+ (setq-local back-button-show-toolbar-buttons nil))
(let ((map (make-sparse-keymap)))
- (tool-bar-local-item "close" #'eb-quit-or-bury 'quit-or-bury map
+ ;; Windows, buffers and files
+ (tool-bar-local-item "cancel" #'eb-quit-or-bury 'quit-or-bury map
:label "Bury" :help "Bury buffer or window")
+ (define-key map [(shift quit-or-bury)] #'eb-exhume-buffer)
+ (define-key map [(control quit-or-bury)] #'delete-other-windows)
(tool-bar-local-item "index" #'eb-list-buffers 'list-buffers map
:label "Buffers" :help "Show project buffers")
+ (define-key map [(shift list-buffers)] #'eb-list-buffers-all)
(tool-bar-local-item "diropen" #'eb-dired 'dired map
:label "Root" :help "Browse project root")
+ (define-key map [(shift dired)] #'eb-dired-here)
+ (tool-bar-local-item "search-replace" #'eb-grep 'grep map
+ :label "Grep" :help "Grep project")
+ ;; Compilation and version control
(define-key-after map [separator-1] menu-bar-separator)
-
+ (tool-bar-local-item "newsticker/next-item" #'eb-run 'run map
+ :label "Run" :help "Run executable")
(tool-bar-local-item "refresh" #'eb-compile 'compile map
:label "Compile" :help "Compile project")
- (tool-bar-local-item "search-replace" #'projectile-grep 'grep map
- :label "Grep" :help "Grep project")
- (tool-bar-local-item "connect" #'eb-vc 'vc map
+ (tool-bar-local-item "info" #'eb-check 'check map
+ :label "Check" :help "Check warnings and errors")
+ (define-key map [(shift check)] #'flycheck-buffer)
+ (define-key map [(control check)] #'flycheck-mode)
+ (tool-bar-local-item "mail/inbox" #'eb-vc 'vc map
:label "Version Control" :help "Open project version control")
- (define-key-after map [separator-2] menu-bar-separator)
-
- ;; back-button
- (tool-bar-local-item "left-arrow"
- 'back-button-global-backward
- 'back-button
- map
- :label "Back By Mark"
- :visible '(and back-button-mode))
- (tool-bar-local-item "mpc/add"
- 'back-button-push-mark-local-and-global
- 'back-button-push
- map
- :label "push Mark"
- :visible '(and back-button-mode))
- (tool-bar-local-item "right-arrow"
- 'back-button-global-forward
- 'forward-button
- map
- :label "Forward By Mark"
- :visible '(and back-button-mode))
+ (when (require 'back-button nil t)
+ (define-key-after map [separator-2] menu-bar-separator)
+ (tool-bar-local-item "left-arrow" #'back-button-global-backward 'previous-mark map
+ :label "Previous Mark" :help "Previous Mark")
+ (define-key map [(shift previous-mark)] #'back-button-local-backward)
+ (tool-bar-local-item "mpc/add" #'back-button-push-mark-local-and-global 'push-mark map
+ :label "Push Mark" :help "Push Mark")
+ (define-key map [(shift push-mark)] #'back-button-push-mark)
+ (tool-bar-local-item "right-arrow" #'back-button-global-forward 'next-mark map
+ :label "Next Mark" :help "Next Mark")
+ (define-key map [(shift next-mark)] #'back-button-local-forward))
+
(setq-local tool-bar-map map)))
(setq-local tool-bar-map eb-tool-bar-mode--old-map)
- (if (not eb-tool-bar-mode--old-back-button-mode)
- (back-button-mode 0))
- (setq-local back-button-show-toolbar-buttons eb-tool-bar-mode--old-back-button-show-toolbar-buttons)))
+ (when (require 'back-button nil t)
+ (if (not eb-tool-bar-mode--old-back-button-mode)
+ (back-button-mode 0))
+ (setq-local back-button-show-toolbar-buttons eb-tool-bar-mode--old-back-button-show-toolbar-buttons))))
(define-global-minor-mode global-eb-tool-bar-mode eb-tool-bar-mode
- (lambda () (eb-tool-bar-mode 1)))
+ (lambda () (eb-tool-bar-mode 1))
+ :group 'eb)
(provide 'eb)
;;; eb.el ends here