summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2023-04-25 14:09:15 +0100
committerYann Herklotz <git@yannherklotz.com>2023-04-25 14:09:56 +0100
commit7a5ef7b149a2fe0b816ff05b1c4b1c2641a7dce1 (patch)
tree00663a46b94bde059180eeff6ac42259d3518a1b
parent5d4cadf99d7eb789b64d04f863e15b04ec04cf0e (diff)
downloadymh-emacs-7a5ef7b149a2fe0b816ff05b1c4b1c2641a7dce1.tar.gz
ymh-emacs-7a5ef7b149a2fe0b816ff05b1c4b1c2641a7dce1.zip
Add ymh-tabs-switch-project function
-rw-r--r--init.el14
-rw-r--r--ymh-emacs/ymh-common.el3
-rw-r--r--ymh-emacs/ymh-diary.el3
-rw-r--r--ymh-emacs/ymh-ebib.el3
-rw-r--r--ymh-emacs/ymh-emacs.el17
-rw-r--r--ymh-emacs/ymh-tabs.el40
6 files changed, 61 insertions, 19 deletions
diff --git a/init.el b/init.el
index 177cd5f..4f9e5de 100644
--- a/init.el
+++ b/init.el
@@ -111,8 +111,10 @@ Should be one of `:white-split', `:modified' or `:default'")
(package-install 'use-package))
;; Load my local library of common emacs functions.
-(use-package ymh-common
- :load-path "ymh-emacs")
+(use-package ymh-emacs
+ :load-path "ymh-emacs"
+ :config
+ (define-key ebib-index-mode-map "D" #'ymh-ebib-download-pdf-from-doi))
;; This is the main configuration block for vanilla emacs.
(use-package emacs
@@ -270,9 +272,6 @@ Should be one of `:white-split', `:modified' or `:default'")
:config
(display-time-mode 1))
-(use-package ymh-diary
- :load-path "ymh-emacs")
-
(use-package whitespace
:config
(defun ymh/add-hook-before-save-hook ()
@@ -882,11 +881,6 @@ https://yannherklotz.com"))
(replace-regexp-in-string ":" "" (apply orig-func args))))
(remove-hook 'ebib-notes-new-note-hook #'org-narrow-to-subtree))
-(use-package ymh-ebib
- :load-path "ymh-emacs"
- :config
- (define-key ebib-index-mode-map "D" #'ymh-ebib-download-pdf-from-doi))
-
(use-package spell-fu
:ensure t
:hook text-mode
diff --git a/ymh-emacs/ymh-common.el b/ymh-emacs/ymh-common.el
index 8f36973..8066f3c 100644
--- a/ymh-emacs/ymh-common.el
+++ b/ymh-emacs/ymh-common.el
@@ -1,8 +1,5 @@
;;; ymh-common.el --- Some common functions -*- lexical-binding: t; -*-
-;; Author: Yann Herklotz <git@yannherklotz.com>
-;; Package-Requires: ((emacs "24.3"))
-
;;; Commentary:
;; This file contains some common code.
diff --git a/ymh-emacs/ymh-diary.el b/ymh-emacs/ymh-diary.el
index 817eedb..c026292 100644
--- a/ymh-emacs/ymh-diary.el
+++ b/ymh-emacs/ymh-diary.el
@@ -1,8 +1,5 @@
;;; ymh-diary.el --- Extensions to the Emacs Diary -*- lexical-binding: t; -*-
-;; Author: Yann Herklotz <git@yannherklotz.com>
-;; Package-Requires: ((emacs "24.3"))
-
;;; Commentary:
;; This file contains extensions to the built-in Emacs Diary. Mainly, it adds a
diff --git a/ymh-emacs/ymh-ebib.el b/ymh-emacs/ymh-ebib.el
index 8c10e3a..8da184f 100644
--- a/ymh-emacs/ymh-ebib.el
+++ b/ymh-emacs/ymh-ebib.el
@@ -1,8 +1,5 @@
;;; ymh-ebib.el --- Extensions to the Ebib package -*- lexical-binding: t; -*-
-;; Author: Yann Herklotz <git@yannherklotz.com>
-;; Package-Requires: ((emacs "26.1") (ebib "2.0"))
-
;;; Commentary:
;; This file contains extensions to ebib.
diff --git a/ymh-emacs/ymh-emacs.el b/ymh-emacs/ymh-emacs.el
new file mode 100644
index 0000000..29a761d
--- /dev/null
+++ b/ymh-emacs/ymh-emacs.el
@@ -0,0 +1,17 @@
+;;; ymh-emacs.el --- Extensions to Emacs -*- lexical-binding: t; -*-
+
+;; Author: Yann Herklotz <git@yannherklotz.com>
+;; Package-Requires: ((emacs "24.3"))
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ymh-common)
+(require 'ymh-diary)
+(require 'ymh-ebib)
+(require 'ymh-tabs)
+
+(provide 'ymh-emacs)
+
+;;; ymh-emacs.el ends here
diff --git a/ymh-emacs/ymh-tabs.el b/ymh-emacs/ymh-tabs.el
new file mode 100644
index 0000000..ea36f6e
--- /dev/null
+++ b/ymh-emacs/ymh-tabs.el
@@ -0,0 +1,40 @@
+;;; ymh-tabs.el --- Extensions to organising tabs -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;; Initially inspired by
+;; https://mihaiolteanu.me/emacs-workspace-management.html.
+
+;;; Code:
+
+(defun ymh-tabs--create (name)
+ "Create the NAME tab if it doesn't exist already."
+ (condition-case nil
+ (unless (equal (alist-get 'name (tab-bar--current-tab))
+ name)
+ (tab-bar-rename-tab-by-name name name)
+ nil)
+ (error (tab-new)
+ (tab-bar-rename-tab name)
+ t)))
+
+(defun ymh-tabs--get-name-from-path (dir)
+ "Get a tab name from a project path DIR."
+ (file-name-base (directory-file-name dir)))
+
+(defun ymh-tabs-switch-project (dir)
+ "\"Switch\" to another project by running an Emacs command.
+The available commands are presented as a dispatch menu
+made from `project-switch-commands'.
+
+When called in a program, it will use the project corresponding
+to directory DIR."
+ (interactive (list (project-prompt-project-dir)))
+ (let ((proj-name (ymh-tabs--get-name-from-path dir)))
+ (if (ymh-tabs--create proj-name)
+ (project-switch-project dir)
+ (tab-bar-switch-to-tab proj-name))))
+
+(provide 'ymh-tabs)
+
+;;; ymh-tabs.el ends here