From e2807445bbf814b03a84258745e171aa134cd170 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 4 Jun 2013 01:51:09 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ README.org | 26 ++++++++++++++ desktop-registry.el | 85 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 .gitignore create mode 100644 README.org create mode 100644 desktop-registry.el diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be341d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.emacs.desktop* +*.elc diff --git a/README.org b/README.org new file mode 100644 index 0000000..8d31e3e --- /dev/null +++ b/README.org @@ -0,0 +1,26 @@ +#+TITLE: Desktop registry +#+STARTUP: showall + +After reading [[https://ericjmritz.wordpress.com/2013/05/28/emacs-desktops/][this post]] I started using =desktop.el= as a simple project +file-like system. The only problem was that remembering which desktops +were where and switching between them is bothersome. This module tries +to fix that. + +* Installation + + If you have [[http://marmalade-repo.org/][Marmalade]] set up you can just use: + + : M-x package-install desktop-registry + +* Usage + + You can use =desktop-registry-prepend-directory= to add a new + directory to the registry, or + =desktop-registry-prepend-current-desktop= to add the currently loaded + desktop to the registry. If you enable + =desktop-registry-auto-register= it will automatically add new desktop + files to the registry when you use =desktop-save=. + + To switch between desktops you can use + =desktop-registry-change-desktop=, this will prompt (with completion) + for the directory you would like to load. diff --git a/desktop-registry.el b/desktop-registry.el new file mode 100644 index 0000000..6aaef14 --- /dev/null +++ b/desktop-registry.el @@ -0,0 +1,85 @@ +;; -*- lexical-binding: t -*- +;;; desktop-registry.el --- Keep a central registry of desktop files + +;; Copyright (C) 2013 Tom Willemse + +;; Author: Tom Willemse +;; Keywords: convenience +;; Version: 1.0.0 + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; This module provides functions and a global minor mode that lets +;; you track a central registry of desktop files. This is useful when +;; you use desktop files as project files and want to be able to +;; switch between them quickly. + +(require 'desktop) + +;;; Code: + +(defgroup desktop-registry nil + "Customization group for desktop-registry." + :group 'desktop + :prefix 'desktop-registry) + +(defcustom desktop-registry-registry nil + "The registry of desktop files." + :group 'desktop-registry + :type '(repeat (cons string directory))) + +(defvar desktop-registry--history nil + "History variable for `desktop-registry'.") + +;;;###autoload +(defun desktop-registry-add-directory (dir) + "Add DIR to the desktop registry." + (interactive "DDirectory: ") + (let* ((clean-dir (directory-file-name (expand-file-name dir))) + (label (file-name-base clean-dir))) + (unless (assoc label desktop-registry-registry) + (customize-save-variable + 'desktop-registry-registry + (cons (cons label clean-dir) desktop-registry-registry))))) + +;;;###autoload +(defun desktop-registry-add-current-desktop () + "Add the currently opened desktop file to `desktop-registry-registry'." + (interactive) + (unless desktop-dirname + (error "No desktop loaded")) + (desktop-registry-add-directory desktop-dirname)) + +;;;###autoload +(defun desktop-registry-change-desktop (name) + "Change to the desktop named NAME." + (interactive + (list (completing-read "Directory: " desktop-registry-registry nil nil + nil 'desktop-registry--history))) + (desktop-change-dir (cdr (assoc name desktop-registry-registry)))) + +;;;###autoload +(define-minor-mode desktop-registry-auto-register + "Automatically add saved desktops to the registry." + :global t + (if desktop-registry-auto-register + (add-hook 'desktop-save-hook + 'desktop-registry-add-current-desktop) + (remove-hook 'desktop-save-hook + 'desktop-registry-add-current-desktop))) + +(provide 'desktop-registry) +;;; desktop-registry.el ends here