Changeset - 5a6c3a89c877
[Not reviewed]
.travis.yml
Show inline comments
 
language: emacs-lisp
 

	
 
env:
 
  global:
 
    - CURL=curl -fsSkL --retry 9 --retry-delay 9
 
  matrix:
 
    - EMACS=emacs AKA=emacs23
 
    - EMACS=emacs24
 
    - EMACS=emacs-snapshot
 

	
 
before_install:
 
  - sudo add-apt-repository -y ppa:cassou/emacs
 
  - sudo apt-get update -qq
 
  - sudo apt-get install -qq $EMACS
 
install:
 
  - if test $EMACS = emacs; then
 
    sudo apt-get install -qq emacs23-el;
 
    $CURL http://elpa.gnu.org/packages/cl-lib-0.4.el -o src/cl-lib.el;
 
    fi
 
  - if [ "$EMACS" = "emacs24" ]; then
 
      sudo apt-get install -qq emacs24-el;
 
    fi
 
  - if [ "$EMACS" = "emacs-snapshot" ]; then
 
      sudo apt-get install -qq emacs-snapshot-el emacs-snapshot-gtk;
 
    fi
Makefile
Show inline comments
 
@@ -16,13 +16,13 @@ clean:
 

	
 
test: clean
 
# just load all files
 
	${EMACS} -L src $(BATCHFLAGS) -f batch-byte-compile $(TEST_DIR)/*.el
 

	
 
# wg-mode-line-string
 
	${EMACS} -L src -batch -l workgroups-functions.el --eval '(message (wg-mode-line-string))'
 
	${EMACS} -L src -batch -l workgroups-modeline.el --eval '(message (wg-mode-line-string))'
 

	
 
# desktop-save-mode
 
	${EMACS} $(FLAGS) --eval "(desktop-save-mode 1)" --eval "(workgroups-mode 1)"
 

	
 
# WGs list length
 
	${EMACS} $(FLAGSWG) --eval "(message (number-to-string (length (wg-workgroup-list))))"
README.md
Show inline comments
 
@@ -39,20 +39,19 @@ By default prefix is: "C-c z" (To change it - see settings below)
 
If you want to change some settings - here is an example:
 

	
 
    (require 'workgroups2)
 
    ;; Your settings here
 

	
 
    ;; autoload/autosave:
 
    ;; if you start Emacs as "emacs --daemon" - turn off autoloading of workgroups:
 
    ;;(setq wg-use-default-session-file nil)
 
    ;;(setq wg-session-load-on-start nil)
 

	
 
    ;; Change prefix key (before activating WG)
 
    (setq wg-prefix-key (kbd "C-c z"))
 

	
 
    ;; Change workgroups session file
 
    (setq wg-default-session-file "~/.emacs.d/.emacs_workgroups")
 
    (setq wg-session-file "~/.emacs.d/.emacs_workgroups")
 

	
 
    ;; Set your own keyboard shortcuts to reload/save/switch WG:
 
    (global-set-key (kbd "<pause>")     'wg-reload-session)
 
    (global-set-key (kbd "C-S-<pause>") 'wg-save-session)
 
    (global-set-key (kbd "s-z")         'wg-switch-to-workgroup)
 
    (global-set-key (kbd "s-/")         'wg-switch-to-previous-workgroup)
src/workgroups-advice.el
Show inline comments
 
;;; workgroups-advice --- change some functions behaviour
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'workgroups-utils-basic)
 
(require 'workgroups-functions)
 

	
 
;; buffer auto-association advice
 

	
 
(defun wg-auto-associate-buffer-helper (workgroup buffer assoc)
 
  "Associate BUFFER with WORKGROUP based on ASSOC.
 
See `wg-buffer-auto-association' for allowable values of ASSOC."
 
  (cond ((memq assoc '(weak strong))
 
         (wg-workgroup-associate-bufobj workgroup buffer (eq assoc 'weak)))
 
        ((functionp assoc)
 
         (wg-auto-associate-buffer-helper
 
          workgroup buffer (funcall assoc workgroup buffer)))
 
        (t nil)))
 

	
 
(defun wg-auto-associate-buffer (buffer &optional frame)
 
  "Conditionally associate BUFFER with the current workgroup in FRAME.
 
Frame defaults to `selected-frame'.  See `wg-buffer-auto-association'."
 
  (when wg-buffer-auto-association-on
 
    (wg-when-let ((wg (wg-current-workgroup t frame)))
 
      (unless (wg-workgroup-bufobj-association-type wg buffer)
 
        (wg-auto-associate-buffer-helper
 
         wg buffer (wg-local-value 'wg-buffer-auto-association wg))))))
 

	
 
(defadvice switch-to-buffer (after wg-auto-associate-buffer)
 
  "Automatically associate the buffer with the current workgroup."
 
  (wg-auto-associate-buffer ad-return-value))
 

	
 
(defadvice set-window-buffer (after wg-auto-associate-buffer)
 
  "Automatically associate the buffer with the current workgroup."
 
  (wg-auto-associate-buffer
 
   (ad-get-arg 1)
 
   (window-frame (or (ad-get-arg 0) (selected-window)))))
 
(require 'workgroups-session)
 

	
 

	
 
;; `wg-pre-window-configuration-change-hook' implementation advice
 

	
 
(cl-macrolet ((define-p-w-c-c-h-advice
 
             (fn)
 
             `(defadvice ,fn (before wg-pre-window-configuration-change-hook)
 
                "Call `wg-update-working-wconfig-hook' before this
 
function to save up-to-date undo information before the
 
window-configuration changes."
 
@@ -85,19 +53,17 @@ Before selecting a new frame."
 
  ;;
 
  ;; (defmacro ad-define-subr-args (subr arglist)
 
  ;;   `(put ,subr 'ad-subr-arglist (list ,arglist)))
 

	
 
  ;; switch-to-buffer
 
  ;; (ad-define-subr-args 'switch-to-buffer '(buffer-or-name &optional norecord))
 
  (ad-enable-advice 'switch-to-buffer 'after 'wg-auto-associate-buffer)
 
  (ad-enable-advice 'switch-to-buffer 'before 'wg-pre-window-configuration-change-hook)
 
  (ad-activate 'switch-to-buffer)
 

	
 
  ;; set-window-buffer
 
  ;; (ad-define-subr-args 'set-window-buffer '(window buffer-or-name &optional keep-margins))
 
  (ad-enable-advice 'set-window-buffer 'after 'wg-auto-associate-buffer)
 
  (ad-enable-advice
 
   'set-window-buffer 'before 'wg-pre-window-configuration-change-hook)
 
  (ad-activate 'set-window-buffer)
 

	
 
  ;; split-window
 
  (ad-enable-advice
 
@@ -138,18 +104,16 @@ Before selecting a new frame."
 
;; disable all advice
 
;; (wg-disable-all-advice)
 
(defun wg-disable-all-advice ()
 
  "Disable and deactivate all of Workgroups' advice."
 

	
 
  ;; switch-to-buffer
 
  (ad-disable-advice 'switch-to-buffer 'after 'wg-auto-associate-buffer)
 
  (ad-disable-advice 'switch-to-buffer 'before 'wg-pre-window-configuration-change-hook)
 
  (ad-deactivate 'switch-to-buffer)
 

	
 
  ;; set-window-buffer
 
  (ad-disable-advice 'set-window-buffer 'after 'wg-auto-associate-buffer)
 
  (ad-disable-advice
 
   'set-window-buffer 'before 'wg-pre-window-configuration-change-hook)
 
  (ad-deactivate 'set-window-buffer)
 

	
 
  ;; split-window
 
  (ad-disable-advice
src/workgroups-buf.el
Show inline comments
 
new file 100644
 
;;; workgroups-buf.el --- BUFFER class
 
;;; Commentary:
 
;;
 
;; Workgroups Data Structures:
 
;;   https://github.com/pashinin/workgroups2/wiki/Workgroups-data-structures
 
;;
 
;;
 
;; BUFFER is the most low level part Workgroups operates with (except
 
;; serializing Emacs objects functions).
 
;;
 
;; Different buffers we have:
 
;;  - live buffers     (just switch-to them)
 
;;  - files/dirs       (open them)
 
;;  - special buffers  (shells, unknown modes - write support for them)
 
;;
 
;; Another different types of "buffers":
 
;;  - standard Emacs buffer (as you know it)
 
;;  - Workgroups Buffer object (Elisp object, a representation of Emacs buffer)
 
;;; Code:
 

	
 
(require 'workgroups-pickel)
 
(require 'workgroups-specialbufs)
 
(require 'workgroups-structs)
 

	
 
;;; Variables
 

	
 
(defvar wg-buffer-workgroup nil
 
  "A workgroup in which this buffer most recently appeared.
 
Buffer-local.")
 
(make-variable-buffer-local 'wg-buffer-workgroup)
 

	
 
(defcustom wg-default-buffer "*scratch*"
 
  "Show this in case everything else fails.
 
When a buffer can't be restored, when creating a blank wg."
 
  :type 'string
 
  :group 'workgroups)
 

	
 

	
 
;;; Functions
 

	
 
(defmacro wg-buf-list ()
 
  "Setf'able `wg-current-session' buf-list slot accessor."
 
  `(wg-session-buf-list (wg-current-session)))
 

	
 
(defun wg-restore-default-buffer ()
 
  "Switch to `wg-default-buffer'."
 
  (switch-to-buffer wg-default-buffer t))
 

	
 
(defun wg-restore-existing-buffer (buf)
 
  "Just switch to and return existing buffer."
 
  (wg-awhen (wg-find-buf-in-buffer-list buf (buffer-list))
 
    (switch-to-buffer it t)
 
    (wg-set-buffer-uid-or-error (wg-buf-uid buf))
 
    it))
 

	
 
(defun wg-restore-file-buffer (buf)
 
  "Restore BUF by finding its file.  Return the created buffer.
 
If BUF's file doesn't exist, call `wg-restore-default-buffer'"
 
  (wg-when-let ((file-name (wg-buf-file-name buf)))
 
    (when (or wg-restore-remote-buffers
 
              (not (file-remote-p file-name)))
 
      (cond ((file-exists-p file-name)
 
             (find-file file-name)
 
             (rename-buffer (wg-buf-name buf) t)
 
             (wg-set-buffer-uid-or-error (wg-buf-uid buf))
 
             (when wg-restore-mark
 
               (set-mark (wg-buf-mark buf))
 
               (deactivate-mark))
 
             (wg-deserialize-buffer-local-variables buf)
 
             (current-buffer))
 
            (t
 
             ;; try directory
 
             (if (not (file-remote-p file-name))
 
                 (if (file-directory-p (file-name-directory file-name))
 
                     (progn
 
                       (dired (file-name-directory file-name))
 
                       (current-buffer))
 
                   (progn
 
                     (message "Attempt to restore nonexistent file: %S" file-name)
 
                     nil))
 
               nil)
 
             )))))
 

	
 
(defun wg-restore-special-buffer (buf)
 
  "Restore a buffer BUF with DESERIALIZER-FN."
 
  (wg-when-let
 
      ((special-data (wg-buf-special-data buf))
 
       (buffer (save-window-excursion
 
                 (condition-case err
 
                     (funcall (car special-data) buf)
 
                   (error (message "Error deserializing %S: %S"
 
                                   (wg-buf-name buf) err)
 
                          nil)))))
 
    (switch-to-buffer buffer t)
 
    (wg-set-buffer-uid-or-error (wg-buf-uid buf))
 
    buffer))
 

	
 
(defun wg-restore-buffer (buf)
 
  "Restore BUF and return it."
 
  (or (wg-restore-existing-buffer buf)
 
      (wg-restore-special-buffer buf)
 
      (wg-restore-file-buffer buf)
 
      (progn (wg-restore-default-buffer) nil)))
 

	
 

	
 
;;; buffer object utils
 

	
 
(defun wg-buffer-uid (buffer-or-name)
 
  "Return BUFFER-OR-NAME's buffer-local value of `wg-buffer-uid'."
 
  (buffer-local-value 'wg-buffer-uid (wg-get-buffer buffer-or-name)))
 

	
 
(defun wg-bufobj-uid (bufobj)
 
  "Return BUFOBJ's uid."
 
  (cl-etypecase bufobj
 
    (buffer (wg-buffer-uid bufobj))
 
    (wg-buf (wg-buf-uid bufobj))
 
    (string (wg-bufobj-uid (wg-get-buffer bufobj)))))
 

	
 
(defun wg-bufobj-name (bufobj)
 
  "Return BUFOBJ's buffer name."
 
  (cl-etypecase bufobj
 
    (buffer (buffer-name bufobj))
 
    (wg-buf (wg-buf-name bufobj))
 
    (string (wg-buffer-name bufobj))))
 

	
 
(defun wg-bufobj-file-name (bufobj)
 
  "Return BUFOBJ's filename."
 
  (cl-etypecase bufobj
 
    (buffer (buffer-file-name bufobj))
 
    (wg-buf (wg-buf-file-name bufobj))
 
    (string (wg-bufobj-file-name (wg-get-buffer bufobj)))))
 

	
 
(defun wg-buf-major-mode (buf)
 
  "Return BUF's `major-mode'.
 
It's stored in BUF's local-vars list, since it's a local variable."
 
  (wg-aget (wg-buf-local-vars buf) 'major-mode))
 

	
 
(defun wg-buffer-major-mode (bufobj)
 
  "Return BUFOBJ's `major-mode'.
 
It works with Emacs buffer, Workgroups buffer object and a simple string."
 
  (cl-etypecase bufobj
 
    (buffer (wg-buffer-major-mode bufobj))
 
    (wg-buf (wg-buf-major-mode bufobj))
 
    (string (wg-buffer-major-mode bufobj))))
 

	
 
;; `wg-equal-bufobjs' and `wg-find-bufobj' may need to be made a lot smarter
 
(defun wg-equal-bufobjs (bufobj1 bufobj2)
 
  "Return t if BUFOBJ1 is \"equal\" to BUFOBJ2."
 
  (let ((fname1 (wg-bufobj-file-name bufobj1))
 
        (fname2 (wg-bufobj-file-name bufobj2)))
 
    (cond ((and fname1 fname2) (string= fname1 fname2))
 
          ((or fname1 fname2) nil)
 
          ((string= (wg-bufobj-name bufobj1) (wg-bufobj-name bufobj2)) t))))
 

	
 
(defun wg-find-bufobj (bufobj bufobj-list)
 
  "Find BUFOBJ in BUFOBJ-LIST, testing with `wg-equal-bufobjs'."
 
  (cl-find bufobj bufobj-list :test 'wg-equal-bufobjs))
 

	
 
(defun wg-find-bufobj-by-uid (uid bufobj-list)
 
  "Find the bufobj in BUFOBJ-LIST with uid UID."
 
  (cl-find uid bufobj-list :test 'string= :key 'wg-bufobj-uid))
 

	
 
(defun wg-find-buf-in-buf-list (buf buf-list)
 
  "Find BUF in BUF-LIST.
 
This is only here for completeness."
 
  (cl-find buf buf-list))
 

	
 
(defun wg-find-buffer-in-buffer-list (buffer-or-name buffer-list)
 
  "Find BUFFER-OR-NAME in BUFFER-LIST."
 
  (cl-find (wg-get-buffer buffer-or-name) buffer-list :key 'wg-get-buffer))
 

	
 
(defun wg-find-buffer-in-buf-list (buffer-or-name buf-list)
 
  "Find BUFFER-OR-NAME in BUF-LIST."
 
  (wg-aif (wg-buffer-uid buffer-or-name)
 
      (wg-find-bufobj-by-uid it buf-list)
 
    (wg-find-bufobj buffer-or-name buf-list)))
 

	
 
(defun wg-find-buf-in-buffer-list (buf buffer-list)
 
  "Find BUF in BUFFER-LIST."
 
  (or (wg-find-bufobj-by-uid (wg-buf-uid buf) buffer-list)
 
      (wg-find-bufobj buf buffer-list)))
 

	
 
(defun wg-find-buf-by-uid (uid)
 
  "Find a buf in `wg-buf-list' by UID."
 
  (wg-find-bufobj-by-uid uid (wg-buf-list)))
 

	
 
(defun wg-set-buffer-uid-or-error (uid &optional buffer)
 
  "Set BUFFER's buffer local value of `wg-buffer-uid' to UID.
 
If BUFFER already has a buffer local value of `wg-buffer-uid',
 
and it's not equal to UID, error."
 
  (if wg-buffer-uid
 
      ;;(if (string= wg-buffer-uid uid) uid
 
      ;;  (error "uids don't match %S and %S" uid wg-buffer-uid))
 
      (setq wg-buffer-uid uid)))
 

	
 

	
 
(defun wg-buffer-special-data (buffer)
 
  "Return BUFFER's auxiliary serialization, or nil."
 
  (cl-some (lambda (fn) (funcall fn buffer)) wg-special-buffer-serdes-functions))
 

	
 

	
 
(defun wg-serialize-buffer-local-variables ()
 
  "Return an alist of buffer-local variable symbols and their values.
 
See `wg-buffer-local-variables-alist' for details."
 
  (wg-docar (entry wg-buffer-local-variables-alist)
 
    (wg-dbind (var ser des) entry
 
      (when (local-variable-p var)
 
        (cons var (if ser (funcall ser) (symbol-value var)))))))
 

	
 
(defun wg-buffer-to-buf (buffer)
 
  "Return the serialization (a wg-buf) of Emacs buffer BUFFER."
 
  (with-current-buffer buffer
 
    (wg-make-buf
 
     :name           (buffer-name)
 
     :file-name      (buffer-file-name)
 
     :point          (point)
 
     :mark           (mark)
 
     :local-vars     (wg-serialize-buffer-local-variables)
 
     :special-data   (wg-buffer-special-data buffer))))
 

	
 
(defun wg-add-buffer-to-buf-list (buffer)
 
  "Make a buf from BUFFER, and add it to `wg-buf-list' if necessary.
 
If there isn't already a buf corresponding to BUFFER in
 
`wg-buf-list', make one and add it.  Return BUFFER's uid
 
in either case."
 
  (with-current-buffer buffer
 
    (setq wg-buffer-uid
 
          (wg-aif (wg-find-buffer-in-buf-list buffer (wg-buf-list))
 
              (wg-buf-uid it)
 
            (let ((buf (wg-buffer-to-buf buffer)))
 
              (push buf (wg-buf-list))
 
              (wg-buf-uid buf))))))
 

	
 
(defun wg-buffer-uid-or-add (buffer)
 
  "Return BUFFER's uid.
 
If there isn't already a buf corresponding to BUFFER in
 
`wg-buf-list', make one and add it."
 
  (or (wg-buffer-uid buffer) (wg-add-buffer-to-buf-list buffer)))
 

	
 
(defun wg-bufobj-uid-or-add (bufobj)
 
  "If BUFOBJ is a wg-buf, return its uid.
 
If BUFOBJ is a buffer or a buffer name, see `wg-buffer-uid-or-add'."
 
  (cl-etypecase bufobj
 
    (wg-buf (wg-buf-uid bufobj)) ;; possibly also add to `wg-buf-list'
 
    (buffer (wg-buffer-uid-or-add bufobj))
 
    (string (wg-bufobj-uid-or-add (wg-get-buffer bufobj)))))
 

	
 

	
 
(defun wg-reset-buffer (buffer)
 
  "Return BUFFER.
 
Currently only sets BUFFER's `wg-buffer-uid' to nil."
 
  (with-current-buffer buffer (setq wg-buffer-uid nil)))
 

	
 

	
 

	
 
;;; buffer-list-filter commands
 

	
 
(defun wg-next-buffer-internal (buffer-list &optional prev noerror)
 
  "Switch to the next buffer in Workgroups' filtered buffer list."
 
  (when buffer-list
 
    (let* ((cur (current-buffer))
 
           (next (or (wg-cyclic-nth-from-elt cur buffer-list (if prev -1 1))
 
                     (car buffer-list))))
 
      (unless (eq cur next)
 
        (switch-to-buffer next)
 
        (unless prev (bury-buffer cur))
 
        next))))
 

	
 
(defun wg-next-buffer (&optional prev)
 
  "Switch to the next buffer in Workgroups' filtered buffer list.
 
In the post-command message the current buffer is rotated to the
 
middle of the list to more easily see where `wg-previous-buffer'
 
will take you."
 
  (interactive)
 
  (let ((command (if prev 'previous-buffer 'next-buffer)))
 
    (if (not (wg-filter-buffer-list-p))
 
        (call-interactively (wg-prior-mapping workgroups-mode command))
 
      (wg-with-buffer-list-filters command
 
        (wg-awhen (wg-filtered-buffer-list) (wg-next-buffer-internal it prev))
 
        (wg-message (wg-buffer-command-display))))))
 

	
 
(defun wg-previous-buffer ()
 
  "Switch to the next buffer in Workgroups' filtered buffer list."
 
  (interactive)
 
  (wg-next-buffer t))
 

	
 
(defun wg-bury-buffer (&optional buffer-or-name)
 
  "Remove BUFFER-OR-NAME from the current workgroup, bury it,
 
and switch to the next buffer in the buffer-list-filter."
 
  (interactive (list (current-buffer)))
 
  (if (not (wg-filter-buffer-list-p))
 
      (call-interactively (wg-prior-mapping workgroups-mode 'bury-buffer))
 
    (wg-with-buffer-list-filters 'bury-buffer
 
      (wg-next-buffer-internal (wg-filtered-buffer-list))
 
      (bury-buffer buffer-or-name)
 
      (wg-message (wg-buffer-command-display)))))
 

	
 
(defun wg-banish-buffer (&optional buffer-or-name)
 
  "Bury BUFFER-OR-NAME."
 
  (interactive)
 
  (let ((buffer (or buffer-or-name (current-buffer))))
 
    (wg-bury-buffer buffer)))
 

	
 

	
 
(defun wg-update-buffer-in-buf-list (&optional buffer)
 
  "Update BUFFER's corresponding buf in `wg-buf-list'.
 
BUFFER nil defaults to `current-buffer'."
 
  (let ((buffer (or buffer (current-buffer))))
 
    (wg-when-let ((uid (wg-buffer-uid buffer))
 
                  (old-buf (wg-find-buf-by-uid uid))
 
                  (new-buf (wg-buffer-to-buf buffer)))
 
      (setf (wg-buf-uid new-buf) (wg-buf-uid old-buf))
 
      (wg-asetf (wg-buf-list) (cons new-buf (remove old-buf it))))))
 

	
 
(defun wg-update-buf-list (&optional buffer-list)
 
  "Update all bufs in `wg-buf-list' corresponding to buffers in BUFFER-LIST."
 
  (mapc 'wg-update-buffer-in-buf-list (or buffer-list (buffer-list))))
 

	
 

	
 

	
 

	
 
(defun wg-buffer-list-display (buffer-list)
 
  "Return the BUFFER-LIST display string."
 
  (wg-display-internal
 
   'wg-buffer-display
 
   (if wg-center-rotate-buffer-list-display
 
       (wg-center-rotate-list buffer-list) buffer-list)))
 

	
 
(defun wg-buffer-list-filter-display (&optional workgroup blf-id)
 
  "Return a buffer-list-filter display string from WORKGROUP and BLF-ID."
 
  (wg-fontify
 
    "("
 
    (wg-workgroup-name (wg-get-workgroup workgroup))
 
    ":"
 
    (wg-get-buffer-list-filter-val blf-id 'indicator)
 
    ")"))
 

	
 
(defun wg-buffer-list-filter-prompt (prompt &optional workgroup blf-id)
 
  "Return a prompt string from PROMPT indicating WORKGROUP and BLF-ID."
 
  (wg-fontify
 
    prompt " "
 
    (wg-buffer-list-filter-display workgroup blf-id)
 
    ": "))
 

	
 
(defun wg-buffer-command-display (&optional buffer-list)
 
  "Return the buffer command display string."
 
  (concat
 
   (wg-buffer-list-filter-display) ": "
 
   (wg-buffer-list-display (or buffer-list (wg-filtered-buffer-list)))))
 

	
 

	
 
(defun wg-read-buffer (prompt &optional default require-match)
 
  "Workgroups' version of `read-buffer'.
 
Read with PROMT DEFAULT REQUIRE-MATCH."
 
  (if (not (wg-filter-buffer-list-p))
 
      (funcall (wg-read-buffer-function) prompt default require-match)
 
    (wg-with-buffer-list-filters 'read-buffer
 
      (funcall (wg-read-buffer-function)
 
               (wg-buffer-list-filter-prompt
 
                (wg-aif (string-match ": *$" prompt)
 
                    (substring prompt 0 it) prompt))
 
               default require-match))))
 

	
 

	
 

	
 
;;; filtered buffer-list construction
 

	
 
(defun wg-get-buffer-list-filter-id-flexibly (blf-id)
 
  "Return a buffer-list-filter-id one way or another."
 
  (or blf-id wg-current-buffer-list-filter-id 'all))
 

	
 
(defun wg-get-buffer-list-filter-val (id key &optional noerror)
 
  "Return ID's KEY's value in `wg-buffer-list-filter-definitions'.
 
Lots of possible errors here because
 
`wg-buffer-list-filter-definitions' can be modified by the user."
 
  (let ((slot-num (cl-case key (symbol 0) (indicator 1) (constructor 2))))
 
    (if (not slot-num)
 
        (unless noerror
 
          (error "`%S' is not a valid buffer-list-filter definition slot" key))
 
      (let* ((id (wg-get-buffer-list-filter-id-flexibly id))
 
             (entry (assq id (wg-local-value
 
                              'wg-buffer-list-filter-definitions))))
 
        (if (not entry)
 
            (unless noerror
 
              (error "`%S' is an undefined buffer-list-filter" id))
 
          (or (nth slot-num entry)
 
              (unless noerror
 
                (error "Slot `%S' is undefined in `%S's definition"
 
                       key id))))))))
 

	
 
(defun wg-filtered-buffer-list (&optional names workgroup bfl-id initial)
 
  "Return a filtered buffer-list from NAMES, WORKGROUP, BLF-ID and INITIAL.
 
NAMES non-nil means return a list of buffer-names instead of buffer objects.
 
WORKGROUP non-nil should be any workgroup identifier accepted by
 
`wg-get-workgroup'.
 
BLF-ID non-nil should be the identifier of a defined buffer-list-filter.
 
It defaults to `wg-get-buffer-list-filter-val'.
 
INITIAL non-nil should be an initial buffer-list to filter.  It defaults to
 
`wg-interesting-buffers'."
 
  (let ((buffer-list (funcall (wg-get-buffer-list-filter-val
 
                               (wg-get-buffer-list-filter-id-flexibly bfl-id)
 
                               'constructor)
 
                              (wg-get-workgroup workgroup)
 
                              (or initial (wg-interesting-buffers)))))
 
    (if names (mapcar 'wg-buffer-name buffer-list) buffer-list)))
 

	
 

	
 
;; buffer-list filters
 

	
 
(defun wg-buffer-list-filter-all (workgroup initial)
 
  "Return all buffers in INITIAL."
 
  initial)
 

	
 
(defun wg-filter-buffer-list-by-regexp (regexp buffer-list)
 
  "Return only those buffers in BUFFER-LIST with names matching REGEXP."
 
  (cl-remove-if-not (lambda (bname) (string-match regexp bname))
 
                    buffer-list :key 'buffer-name))
 

	
 
(defun wg-filter-buffer-list-by-root-dir (root-dir buffer-list)
 
  "Return only those buffers in BUFFER-LIST visiting files undo ROOT-DIR."
 
  (cl-remove-if-not (lambda (f) (when f (wg-file-under-root-path-p root-dir f)))
 
                    buffer-list :key 'buffer-file-name))
 

	
 
(defun wg-filter-buffer-list-by-major-mode (major-mode buffer-list)
 
  "Return only those buffers in BUFFER-LIST in major-mode MAJOR-MODE."
 
  (cl-remove-if-not (lambda (mm) (eq mm major-mode))
 
                    buffer-list :key 'wg-buffer-major-mode))
 

	
 

	
 
;; Example custom buffer-list-filters
 

	
 
(defun wg-buffer-list-filter-irc (workgroup buffer-list)
 
  "Return only those buffers in BUFFER-LIST with names starting in \"#\"."
 
  (wg-filter-buffer-list-by-regexp "^#" buffer-list))
 

	
 
(defun wg-buffer-list-filter-home-dir (workgroup buffer-list)
 
  "Return only those buffers in BUFFER-LIST visiting files under ~/."
 
  (wg-filter-buffer-list-by-root-dir "~/" buffer-list))
 

	
 

	
 

	
 
;; buffer-list-filter context
 

	
 
(defun wg-buffer-list-filter-order (command)
 
  "Return WORKGROUP's buffer-list-filter order for COMMAND, or a default."
 
  (let ((bfo (wg-local-value 'wg-buffer-list-filter-order-alist)))
 
    (or (wg-aget bfo command) (wg-aget bfo 'default))))
 

	
 
(defmacro wg-prior-mapping (mode command)
 
  "Return whatever COMMAND would call if MODE wasn't on."
 
  `(or (let (,mode) (command-remapping ,command)) ,command))
 

	
 
(defun wg-filter-buffer-list-p ()
 
  "Return the current workgroup when buffer-list-filters are on."
 
  (and workgroups-mode wg-buffer-list-filtration-on (wg-current-workgroup t)))
 

	
 
(defmacro wg-with-buffer-list-filters (command &rest body)
 
  "Create buffer-list filter context for COMMAND, and eval BODY.
 
Binds `wg-current-buffer-list-filter-id' in BODY."
 
  (declare (indent 1))
 
  (wg-with-gensyms (order status)
 
    `(let* ((wg-previous-minibuffer-contents nil)
 
            (,order (wg-buffer-list-filter-order ,command)))
 
       (catch 'wg-result
 
         (while 'your-mom
 
           (let* ((wg-current-buffer-list-filter-id (car ,order))
 
                  (,status (catch 'wg-action (list 'done (progn ,@body)))))
 
             (cl-case (car ,status)
 
               (done (throw 'wg-result (cadr ,status)))
 
               (next (setq ,order (wg-rotate-list ,order 1))
 
                     (setq wg-previous-minibuffer-contents (cadr ,status)))
 
               (prev (setq ,order (wg-rotate-list ,order -1))
 
                     (setq wg-previous-minibuffer-contents
 
                           (cadr ,status))))))))))
 

	
 
(defun wg-toggle-buffer-list-filtration ()
 
  "Toggle `wg-buffer-list-filtration-on'."
 
  (interactive)
 
  (wg-toggle-and-message 'wg-buffer-list-filtration-on))
 

	
 

	
 
(provide 'workgroups-buf)
 
;;; workgroups-buf.el ends here
src/workgroups-commands-minibuffer.el
Show inline comments
 
deleted file
src/workgroups-commands.el
Show inline comments
 
deleted file
src/workgroups-faces.el
Show inline comments
 
new file 100644
 
;;; workgroups-faces.el --- Colors
 
;;; Commentary:
 
;; display customization
 
;;; Code:
 

	
 
(defcustom wg-use-faces t
 
  "Non-nil means use faces in various messages."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-left-brace "( "
 
  "String displayed to the left of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-right-brace " )"
 
  "String displayed to the right of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-divider " | "
 
  "String displayed between elements of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-current-left "-<{ "
 
  "String displayed to the left of the current element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-current-right " }>-"
 
  "String displayed to the right of the current element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-previous-left "< "
 
  "String displayed to the left of the previous element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-previous-right " >"
 
  "String displayed to the right of the previous element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 

	
 
(defvar wg-face-abbrevs nil
 
  "Assoc list mapping face abbreviations to face names.")
 

	
 
(defmacro wg-defface (face key spec doc &rest args)
 
  "`defface' wrapper adding a lookup key used by `wg-fontify'."
 
  (declare (indent 2))
 
  `(progn
 
     (cl-pushnew (cons ,key ',face) wg-face-abbrevs :test #'equal)
 
     (defface ,face ,spec ,doc ,@args)))
 

	
 
(wg-defface wg-current-workgroup-face :cur
 
  '((t :inherit font-lock-constant-face :bold nil))
 
  "Face used for current elements in list displays."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-previous-workgroup-face :prev
 
  '((t :inherit font-lock-keyword-face :bold nil))
 
  "Face used for the name of the previous workgroup in the list display."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-other-workgroup-face :other
 
  '((t :inherit font-lock-string-face :bold nil))
 
  "Face used for the names of other workgroups in the list display."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-command-face :cmd
 
  '((t :inherit font-lock-function-name-face :bold nil))
 
  "Face used for command/operation strings."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-divider-face :div
 
  '((t :inherit font-lock-builtin-face :bold nil))
 
  "Face used for dividers."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-brace-face :brace
 
  '((t :inherit font-lock-builtin-face :bold nil))
 
  "Face used for left and right braces."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-message-face :msg
 
  '((t :inherit font-lock-string-face :bold nil))
 
  "Face used for messages."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-mode-line-face :mode
 
  '((t :inherit font-lock-doc-face :bold nil))
 
  "Face used for workgroup position and name in the mode-line display."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-filename-face :file
 
  '((t :inherit font-lock-keyword-face :bold nil))
 
  "Face used for filenames."
 
  :group 'workgroups)
 

	
 

	
 
;;; fancy displays
 

	
 
(defun wg-element-display (elt elt-string &optional current-elt-p previous-elt-p)
 
  "Return display string for ELT."
 
  (cond ((and current-elt-p (funcall current-elt-p elt))
 
         (wg-fontify (:cur (concat wg-list-display-decor-current-left
 
                                   elt-string
 
                                   wg-list-display-decor-current-right))))
 
        ((and previous-elt-p (funcall previous-elt-p elt))
 
         (wg-fontify (:prev (concat wg-list-display-decor-previous-left
 
                                    elt-string
 
                                    wg-list-display-decor-previous-right))))
 
        (t (wg-fontify (:other elt-string)))))
 

	
 
(defun wg-workgroup-display (workgroup index)
 
  "Return display string for WORKGROUP at INDEX."
 
  (if (not workgroup) wg-nowg-string
 
    (wg-element-display
 
     workgroup
 
     (format "%d: %s" index (wg-workgroup-name workgroup))
 
     'wg-current-workgroup-p
 
     'wg-previous-workgroup-p)))
 

	
 
(defun wg-buffer-display (buffer index)
 
  "Return display string for BUFFER.  INDEX is ignored."
 
  (if (not buffer) "No buffers"
 
    (wg-element-display
 
     (wg-get-buffer buffer)
 
     (format "%s" (wg-buffer-name buffer))
 
     'wg-current-buffer-p)))
 

	
 

	
 
;; (defun wg-display-internal (elt-fn list)
 
;;   "Return display string built by calling ELT-FN on each element of LIST."
 
;;   (let ((div (wg-add-face :div wg-list-display-decor-divider))
 
;;         (i -1))
 
;;     (wg-fontify
 
;;       (:brace wg-list-display-decor-left-brace)
 
;;       (if (not list) (funcall elt-fn nil nil)
 
;;         (wg-doconcat (elt list div) (funcall elt-fn elt (cl-incf i))))
 
;;       (:brace wg-list-display-decor-right-brace))))
 

	
 

	
 

	
 
;;; messaging
 

	
 
(defun wg-message (format-string &rest args)
 
  "Call `message' with FORMAT-STRING and ARGS.
 
Also save the msg to `wg-last-message'."
 
  (setq wg-last-message (apply #'message format-string args)))
 

	
 
(defmacro wg-fontified-message (&rest format)
 
  "`wg-fontify' FORMAT and call `wg-message' on it."
 
  (declare (indent defun))
 
  `(wg-message (wg-fontify ,@format)))
 

	
 
(defun wg-toggle-and-message (symbol)
 
  "Toggle SYMBOL's truthiness and message the new value."
 
  (wg-fontified-message
 
    (:cmd (format "%s: " symbol))
 
    (:msg (format "%s" (wg-toggle symbol)))))
 

	
 

	
 
(defun wg-add-face (facekey string)
 
  "Return a copy of STRING fontified according to FACEKEY.
 
FACEKEY must be a key in `wg-face-abbrevs'."
 
  (let ((face (wg-aget wg-face-abbrevs facekey))
 
        (string  (copy-sequence string)))
 
    (unless face (error "No face with key %s" facekey))
 
    (if (not wg-use-faces) string
 
      (put-text-property 0 (length string) 'face face string)
 
      string)))
 

	
 
(defmacro wg-fontify (&rest specs)
 
  "A small fontification DSL.
 
The results of all SPECS are `concat'd together.
 
If a spec is a cons with a keyword car, apply `wg-add-face' to it.
 
Other conses get evaluated, and should produce a strings.
 
If a spec is a string it is used unmodified.
 
Anything else is formatted with %s to produce a string."
 
  (declare (indent defun))
 
  `(concat
 
    ,@(wg-docar (spec specs)
 
        (cond ((and (consp spec)
 
                    (keywordp (car spec)))
 
               `(wg-add-face ,@spec))
 
              ;;((listp spec) (cdr (eval spec)))
 
              ;;((listp spec)
 
              ;; ;;(prin1-to-string (nth 1 (eval spec)))
 
              ;; )
 
              ((consp spec) spec)
 
              ((stringp spec) spec)
 
              (t `(format "%s" ,spec))))))
 

	
 
(provide 'workgroups-faces)
 
;;; workgroups-faces.el ends here
src/workgroups-functions.el
Show inline comments
 
deleted file
src/workgroups-ido.el
Show inline comments
 
;;; workgroups-ido --- ido and iswitchb compatibility
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'workgroups-variables)
 

	
 
(require 'cl-lib)
 
(eval-when-compile
 
  (require 'ido)
 
  (require 'iswitchb))
 
(require 'ido)
 

	
 
(defcustom wg-ido-entry-buffer-replacement-regexp "^ .*Minibuf.*$"
 
  "Regexp matching the name of a buffer to replace `ido-entry-buffer'.
 
The regexp should match the name of a live buffer that will never
 
be a completion candidate under normal circumstances.  You
 
probably don't want to change this.  See
 
`wg-get-sneaky-ido-entry-buffer-replacement'."
 
  :type 'regexp
 
  :group 'workgroups)
 

	
 

	
 
(defun wg-read-buffer-mode ()
 
  "Return the buffer switching package (ido or iswitchb) to use, or nil."
 
  (if (eq wg-current-buffer-list-filter-id 'fallback) 'fallback
 
    (cl-case (let (workgroups-mode) (command-remapping 'switch-to-buffer))
 
      (ido-switch-buffer 'ido)
 
      (iswitchb-buffer 'iswitchb)
 
      (otherwise 'fallback))))
 

	
 
(defun wg-read-buffer-function (&optional mode)
 
  "Return MODE's or `wg-read-buffer-mode's `read-buffer' function."
 
  (cl-case (or mode (wg-read-buffer-mode))
 
    (ido 'ido-read-buffer)
 
    (iswitchb 'iswitchb-read-buffer)
 
    (fallback (lambda (prompt &optional default require-match)
 
                (let (read-buffer-function)
 
                  (read-buffer prompt default require-match))))))
 

	
 
;; TODO: clean this up
 
(defun wg-completing-read
 
  (prompt choices &optional pred require-match initial-input history default)
 
  "Do a completing read.  The function called depends on what's on."
 
  (cl-ecase (wg-read-buffer-mode)
 
    (ido
 
     (ido-completing-read prompt choices pred require-match
 
                          initial-input history default))
 
    (iswitchb
 
     (let* ((iswitchb-use-virtual-buffers nil)
 
            (iswitchb-make-buflist-hook
 
             (lambda () (setq iswitchb-temp-buflist choices))))
 
       (iswitchb-read-buffer prompt default require-match)))
 
    (fallback
 
     (completing-read prompt choices pred require-match
 
                      initial-input history default))))
 

	
 
(defun wg-current-matches (&optional read-buffer-mode)
 
  "Return READ-BUFFER-MODE's current matches."
 
  (cl-ecase (or read-buffer-mode (wg-read-buffer-mode))
 
    (ido (wg-when-boundp (ido-cur-list) ido-cur-list))
 
    (iswitchb (wg-when-boundp (iswitchb-buflist) iswitchb-buflist))
 
    (fallback (list minibuffer-default))))
 

	
 
(defun wg-current-match (&optional read-buffer-mode)
 
  "Return READ-BUFFER-MODE's current match."
 
  (car (wg-current-matches read-buffer-mode)))
 

	
 
(defun wg-set-current-matches (match-list &optional read-buffer-mode)
 
  "Set READ-BUFFER-MODE's current matches, and flag a rescan."
 
  (cl-case (or read-buffer-mode (wg-read-buffer-mode))
 
    (ido
 
     (wg-when-boundp (ido-cur-list)
 
       (setq ido-cur-list match-list ido-rescan t)))
 
    (iswitchb
 
     (wg-when-boundp (iswitchb-buflist)
 
       (setq iswitchb-buflist match-list iswitchb-rescan t)))
 
    (fallback nil)))
 

	
 
(defun wg-iswitchb-internal (method &optional prompt default init)
 
  "This provides the buffer switching interface to
 
`iswitchb-read-buffer' (analogous to ido's `ido-buffer-internal')
 
that iswitchb *should* have had.  A lot of this code is
 
duplicated from `iswitchb', so is similarly shitty."
 
  (let ((iswitchb-method (if (memq method '(insert kill)) 'samewindow method))
 
        (iswitchb-invalid-regexp nil)
 
        (buffer (iswitchb-read-buffer (or prompt "iswitch ") default nil init)))
 
    (cond ((eq iswitchb-exit 'findfile)
 
           (call-interactively 'find-file))
 
          (iswitchb-invalid-regexp
 
           (message "Won't make invalid regexp named buffer"))
 
          ((not buffer) nil)
 
          ((not (wg-get-buffer buffer))
 
           (iswitchb-possible-new-buffer buffer))
 
          ((eq method 'insert)
 
           (insert-buffer-substring buffer))
 
          ((eq method 'kill)
 
           (kill-buffer buffer))
 
          (t (iswitchb-visit-buffer buffer)))))
 

	
 
(defun wg-buffer-internal (command &optional prompt default)
 
  "Buffer list filtration interface to the current remapping of COMMAND.
 
PROMPT non-nil specifies the prompt.
 
DEFAULT non-nil specifies the first completion candidate."
 
  (if (not (wg-filter-buffer-list-p))
 
      (call-interactively (wg-prior-mapping workgroups-mode command))
 
    (wg-with-buffer-list-filters command
 
      (let ((wg-buffer-internal-default-buffer default))
 
        (cl-ecase (wg-read-buffer-mode)
 
          (ido
 
           (ido-buffer-internal
 
            (wg-aget wg-ido-method-translations command) nil
 
            (wg-buffer-list-filter-prompt prompt)
 
            nil wg-previous-minibuffer-contents))
 
          (iswitchb
 
           (wg-iswitchb-internal
 
            (wg-aget wg-iswitchb-method-translations command)
 
            (wg-buffer-list-filter-prompt prompt)
 
            nil wg-previous-minibuffer-contents))
 
          (fallback
 
           (let (read-buffer-function)
 
             (call-interactively command))))
 
        (wg-message (wg-buffer-command-display))))))
 

	
 
(defun wg-get-sneaky-ido-entry-buffer-replacement (&optional regexp)
 
  "Return a live buffer to replace `ido-entry-buffer'.
 
This is a workaround for an ido misfeature.  IMHO, ido should
 
respect the value of `ido-temp-list' after
 
`ido-make-buffer-list-hook' has been run, since the user's
 
preference for the final value of `ido-temp-list', if any, has
 
@@ -153,13 +85,8 @@ at the beginning of BUFLIST.  Otherwise rotate BUFLIST."
 
  "Set `ido-temp-list' with `wg-set-buffer-list-symbol'.
 
Added to `ido-make-buffer-list-hook'."
 
  (wg-set-buffer-list-symbol 'ido-temp-list)
 
  (wg-when-boundp (ido-entry-buffer)
 
    (setq ido-entry-buffer (wg-get-sneaky-ido-entry-buffer-replacement))))
 

	
 
(defun wg-set-iswitchb-buffer-list ()
 
  "Set `iswitchb-temp-buflist' with `wg-set-buffer-list-symbol'.
 
Added to `iswitchb-make-buflist-hook'."
 
  (wg-set-buffer-list-symbol 'iswitchb-temp-buflist))
 

	
 
(provide 'workgroups-ido)
 
;;; workgroups-ido.el ends here
src/workgroups-keys.el
Show inline comments
 
;;; workgroups.keys.el --- Set default workgroups keys
 
;;; Commentary:
 
;;
 
;;; Code:
 

	
 
(require 'workgroups-variables)
 
(require 'workgroups-utils-basic)
 

	
 
(defcustom wg-prefix-key (kbd "C-c z")
 
  "Workgroups' prefix key.
 
Setting this variable requires that `workgroups-mode' be turned
 
off and then on again to take effect."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defvar workgroups-mode-map nil
 
  "Workgroups Mode's keymap.")
 

	
 
(defvar wg-prefixed-map
 
  (wg-fill-keymap
 
   (make-sparse-keymap)
 

	
 

	
 
   ;; workgroup creation
 

	
 
   ;; workgroups
 
   (kbd "C-c")        'wg-create-workgroup
 
   (kbd "c")          'wg-create-workgroup
 
   (kbd "C")          'wg-clone-workgroup
 
   (kbd "A")          'wg-rename-workgroup
 
   (kbd "C-'")        'wg-switch-to-workgroup
 
   (kbd "'")          'wg-switch-to-workgroup
 
   (kbd "C-v")        'wg-switch-to-workgroup
 
   (kbd "v")          'wg-switch-to-workgroup
 

	
 
   ;; session
 
   (kbd "C-s")        'wg-save-session
 
   (kbd "C-w")        'wg-save-session-as
 
   (kbd "C-f")        'wg-open-session
 

	
 
   ;; killing and yanking
 

	
 
   (kbd "C-k")        'wg-kill-workgroup
 
   (kbd "k")          'wg-kill-workgroup
 
   (kbd "M-W")        'wg-kill-ring-save-base-wconfig
 
   (kbd "M-w")        'wg-kill-ring-save-working-wconfig
 
   (kbd "C-y")        'wg-yank-wconfig
 
   (kbd "y")          'wg-yank-wconfig
 
   (kbd "M-k")        'wg-kill-workgroup-and-buffers
 
   (kbd "K")          'wg-delete-other-workgroups
 

	
 

	
 
   ;; updating and reverting
 

	
 
   (kbd "C-r")        'wg-revert-workgroup
 
   (kbd "r")          'wg-revert-workgroup
 
   (kbd "C-S-r")      'wg-revert-all-workgroups
 
   (kbd "R")          'wg-revert-all-workgroups
 

	
 

	
 
   ;; workgroup switching
 

	
 
   (kbd "C-'")        'wg-switch-to-workgroup
 
   (kbd "'")          'wg-switch-to-workgroup
 
   (kbd "C-v")        'wg-switch-to-workgroup
 
   (kbd "v")          'wg-switch-to-workgroup
 
   (kbd "M-v")        'wg-switch-to-workgroup-other-frame
 
   (kbd "C-j")        'wg-switch-to-workgroup-at-index
 
   (kbd "j")          'wg-switch-to-workgroup-at-index
 
   (kbd "0")          'wg-switch-to-workgroup-at-index-0
 
   (kbd "1")          'wg-switch-to-workgroup-at-index-1
 
   (kbd "2")          'wg-switch-to-workgroup-at-index-2
 
@@ -56,86 +61,60 @@
 
   (kbd "8")          'wg-switch-to-workgroup-at-index-8
 
   (kbd "9")          'wg-switch-to-workgroup-at-index-9
 
   (kbd "C-p")        'wg-switch-to-workgroup-left
 
   (kbd "p")          'wg-switch-to-workgroup-left
 
   (kbd "C-n")        'wg-switch-to-workgroup-right
 
   (kbd "n")          'wg-switch-to-workgroup-right
 
   (kbd "M-p")        'wg-switch-to-workgroup-left-other-frame
 
   (kbd "M-n")        'wg-switch-to-workgroup-right-other-frame
 
   (kbd "C-a")        'wg-switch-to-previous-workgroup
 
   (kbd "a")          'wg-switch-to-previous-workgroup
 

	
 

	
 
   ;; updating and reverting
 
   ;; wconfig undo/redo
 

	
 
   (kbd "C-r")        'wg-revert-workgroup
 
   (kbd "r")          'wg-revert-workgroup
 
   (kbd "C-S-r")      'wg-revert-all-workgroups
 
   (kbd "R")          'wg-revert-all-workgroups
 
   (kbd "<left>")     'wg-undo-wconfig-change
 
   (kbd "<right>")    'wg-redo-wconfig-change
 
   (kbd "[")          'wg-undo-wconfig-change
 
   (kbd "]")          'wg-redo-wconfig-change
 
   (kbd "{")          'wg-undo-once-all-workgroups
 
   (kbd "}")          'wg-redo-once-all-workgroups
 

	
 

	
 
   ;; wconfig save/restore
 

	
 
   ;; FIXME: come up with better keys for these:
 
   (kbd "C-d C-s")    'wg-save-wconfig
 
   (kbd "C-d C-'")    'wg-restore-saved-wconfig
 
   (kbd "C-d C-k")    'wg-kill-saved-wconfig
 

	
 

	
 
   ;; buffer-list
 

	
 
   (kbd "+")          'wg-associate-buffer-with-workgroup
 
   (kbd "~")          'wg-associate-visible-buffers-with-workgroup
 
   (kbd "-")          'wg-dissociate-buffer-from-workgroup
 
   (kbd "=")          'wg-cycle-buffer-association-type
 
   (kbd "*")          'wg-restore-workgroup-associated-buffers
 
   (kbd "_")          'wg-dissociate-weakly-associated-buffers
 
   (kbd "(")          'wg-next-buffer
 
   (kbd ")")          'wg-previous-buffer
 

	
 

	
 
   ;; workgroup movement
 

	
 
   (kbd "C-x")        'wg-swap-workgroups
 
   (kbd "C-,")        'wg-offset-workgroup-left
 
   (kbd "C-.")        'wg-offset-workgroup-right
 

	
 

	
 
   ;; file and buffer
 

	
 
   (kbd "C-s")        'wg-save-session
 
   (kbd "C-w")        'wg-write-session-file
 
   (kbd "C-f")        'wg-find-session-file
 
   (kbd "F")          'wg-find-file-in-new-workgroup
 
   (kbd "M-F")        'wg-find-file-read-only-in-new-workgroup
 
   (kbd "d")          'wg-dired-in-new-workgroup
 
   (kbd "C-b")        'wg-switch-to-buffer
 
   (kbd "b")          'wg-switch-to-buffer
 

	
 

	
 
   ;; window moving and frame reversal
 

	
 
   (kbd "<")          'wg-backward-transpose-window
 
   (kbd ">")          'wg-transpose-window
 
   (kbd "|")          'wg-reverse-frame-horizontally
 
   (kbd "\\")         'wg-reverse-frame-vertically
 
   (kbd "/")          'wg-reverse-frame-horizontally-and-vertically
 

	
 

	
 
   ;; toggling
 

	
 
   (kbd "C-t C-m")    'wg-toggle-mode-line-display
 
   (kbd "C-t C-b")    'wg-toggle-buffer-list-filtration
 
   (kbd "C-t C-d")    'wg-toggle-window-dedicated-p
 

	
 

	
 
   ;; misc
 

	
 
   (kbd "A")          'wg-rename-workgroup
 
   (kbd "!")          'wg-reset
 
   (kbd "?")          'wg-help
 

	
 
   )
 
  "The keymap that sits on `wg-prefix-key'.")
 

	
 
@@ -143,58 +122,17 @@
 
  "Return Workgroups' minor-mode-map.
 
This map includes `wg-prefixed-map' on `wg-prefix-key', as well
 
as Workgroups' command remappings."
 
  (let ((map (make-sparse-keymap)))
 
    (define-key map wg-prefix-key
 
      wg-prefixed-map)
 
    (when wg-remap-switch-to-buffer
 
      (define-key map [remap switch-to-buffer]
 
        'wg-switch-to-buffer))
 
    (when wg-remap-switch-to-buffer-other-window
 
      (define-key map [remap switch-to-buffer-other-window]
 
        'wg-switch-to-buffer-other-window))
 
    (when wg-remap-switch-to-buffer-other-frame
 
      (define-key map [remap switch-to-buffer-other-frame]
 
        'wg-switch-to-buffer-other-frame))
 
    (when wg-remap-next-buffer
 
      (define-key map [remap next-buffer]
 
        'wg-next-buffer))
 
    (when wg-remap-previous-buffer
 
      (define-key map [remap previous-buffer]
 
        'wg-previous-buffer))
 
    (when wg-remap-kill-buffer
 
      (define-key map [remap kill-buffer]
 
        'wg-kill-buffer))
 
    (when wg-remap-display-buffer
 
      (define-key map [remap display-buffer]
 
        'wg-display-buffer))
 
    (when wg-remap-insert-buffer
 
      (define-key map [remap insert-buffer]
 
        'wg-insert-buffer))
 
    (cond ((eq wg-remap-bury-buffer 'banish)
 
           (define-key map [remap bury-buffer]
 
             'wg-banish-buffer))
 
          (wg-remap-bury-buffer
 
           (define-key map [remap bury-buffer]
 
             'wg-bury-buffer)))
 
    ;;(cond ((eq wg-remap-bury-buffer 'banish)
 
    ;;       (define-key map [remap bury-buffer]
 
    ;;         'wg-banish-buffer))
 
    ;;      (wg-remap-bury-buffer
 
    ;;       (define-key map [remap bury-buffer]
 
    ;;         'wg-bury-buffer)))
 
    (setq workgroups-mode-map map)))
 

	
 
(defvar wg-minibuffer-mode-map
 
  (wg-fill-keymap
 
   (make-sparse-keymap)
 
   (kbd "C-b")       'wg-backward-char-or-next-buffer-list-filter
 
   (kbd "C-c n")     'wg-next-buffer-list-filter
 
   (kbd "C-c C-n")   'wg-next-buffer-list-filter
 
   (kbd "C-S-b")     'wg-backward-char-or-previous-buffer-list-filter
 
   (kbd "C-c p")     'wg-previous-buffer-list-filter
 
   (kbd "C-c C-p")   'wg-previous-buffer-list-filter
 
   (kbd "C-c a")     'wg-associate-first-match
 
   (kbd "C-c C-a")   'wg-associate-first-match
 
   (kbd "C-c d")     'wg-dissociate-first-match
 
   (kbd "C-c C-d")   'wg-dissociate-first-match
 
   (kbd "C-c _")     'wg-minibuffer-mode-dissociate-weakly-associated-buffers
 
   )
 
  "`wg-minibuffer-mode's keymap.")
 

	
 

	
 
(provide 'workgroups-keys)
 
;;; workgroups-keys.el ends here
src/workgroups-minibuffer.el
Show inline comments
 
new file 100644
 
;;; wg-commands-minibuffer --- minibuffer commands
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'workgroups-utils-basic)
 
(require 'workgroups-ido)
 
(require 'workgroups-buf)
 

	
 
(defvar wg-just-exited-minibuffer nil
 
  "Flag set by `minibuffer-exit-hook'.
 
To exempt from undoification those window-configuration changes
 
caused by exiting the minibuffer.  This is ugly, but necessary.
 
It may seem like we could just null out
 
`wg-undoify-window-configuration-change' in
 
`minibuffer-exit-hook', but that also prevents undoification of
 
window configuration changes triggered by commands called with
 
`execute-extended-command' -- i.e. it's just too coarse.")
 

	
 
(defcustom wg-no-confirm-on-destructive-operation nil
 
  "Do not request confirmation before various destructive operations.
 
Like `wg-reset'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-minibuffer-message-timeout 0.75
 
  "Bound to `minibuffer-message-timeout' when messaging while the
 
minibuffer is active."
 
  :type 'float
 
  :group 'workgroups)
 

	
 

	
 
;;
 
;; Functions
 
;;
 

	
 
(defun wg-read-object (prompt test warning &optional initial-contents keymap
 
                              read hist default-value inherit-input-method)
 
  "PROMPT for an object that satisfies TEST,
 
WARNING if necessary.  ARGS are `read-from-minibuffer's args,
 
after PROMPT."
 
  (cl-labels ((read () (read-from-minibuffer
 
                        prompt initial-contents keymap read hist
 
                        default-value inherit-input-method)))
 
    (let ((obj (read)))
 
      (when (and (equal obj "") default-value) (setq obj default-value))
 
      (while (not (funcall test obj))
 
        (message warning)
 
        (sit-for wg-minibuffer-message-timeout)
 
        (setq obj (read)))
 
      obj)))
 

	
 
(defun wg-minibuffer-inactive-p ()
 
  "Return t when `minibuffer-depth' is zero, nil otherwise."
 
  (zerop (minibuffer-depth)))
 

	
 

	
 
(defun wg-barf-on-active-minibuffer ()
 
  "Throw an error when the minibuffer is active."
 
  (when (not (wg-minibuffer-inactive-p))
 
    (error "Exit minibuffer to use workgroups functions!")))
 

	
 

	
 
(provide 'workgroups-minibuffer)
 
;;; workgroups-minibuffer.el ends here
src/workgroups-modeline.el
Show inline comments
 
new file 100644
 
;;; workgroups-modeline.el --- All modeline modifications
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'workgroups-keys)
 
(require 'workgroups-workgroup)
 

	
 
(defcustom wg-mode-line-display-on t
 
  "Toggles Workgroups' mode-line display."
 
  :type 'boolean
 
  :group 'workgroups
 
  :set (lambda (sym val)
 
         (custom-set-default sym val)
 
         (force-mode-line-update)))
 

	
 
(defcustom wg-mode-line-use-faces nil
 
  "Non-nil means use faces in the mode-line display.
 
It can be tricky to choose faces that are visible in both active
 
and inactive mode-lines, so this feature defaults to off."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-disable (featurep 'powerline)
 
  "Do not do any modeline modifications.
 
There are problems with powerline."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-only-name t
 
  "Display only workgroup name in modeline without any flags."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-left-brace "("
 
  "String displayed at the left of the mode-line display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-right-brace ")"
 
  "String displayed at the right of the mode-line display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-divider ":"
 
  "String displayed between elements of the mode-line display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-window-dedicated
 
  #("#" 0 1 (help-echo "This window is dedicated to its buffer."))
 
  "Indicates that the window is dedicated to its buffer."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-window-undedicated
 
  #("-" 0 1 (help-echo "This window is not dedicated to its buffer."))
 
  "Indicates that the window is not dedicated to its buffer."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-session-modified
 
  #("*" 0 1 (help-echo "The session is modified"))
 
  "Indicates that the session is modified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-session-unmodified
 
  #("-" 0 1 (help-echo "The session is unmodified"))
 
  "Indicates that the session is unmodified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-workgroup-modified
 
  #("*" 0 1 (help-echo "The current workgroup is modified"))
 
  "Indicates that the current workgroup is modified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-workgroup-unmodified
 
  #("-" 0 1 (help-echo "The current workgroup is unmodified"))
 
  "Indicates that the current workgroup is unmodified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 

	
 

	
 
;;; mode-line
 

	
 
(defun wg-mode-line-string ()
 
  "Return the string to be displayed in the mode-line."
 
  (let ((wg (wg-current-workgroup t))
 
        (wg-use-faces wg-mode-line-use-faces))
 
    (cond (wg (wg-fontify " "
 
                ;;(consp (cons :div wg-mode-line-decor-left-brace))
 
                ;;(keywordp (car (cons :div wg-mode-line-decor-left-brace)))
 
                ;;(:div wg-mode-line-decor-left-brace)
 
                (:brace wg-mode-line-decor-left-brace)
 
                (:mode (wg-workgroup-name wg))
 
                (if (not wg-mode-line-only-name)
 
                    (concat
 
                     (wg-add-face :div wg-mode-line-decor-divider)
 
                     (wg-add-face :div wg-mode-line-decor-divider)
 
                     (if (window-dedicated-p)
 
                         wg-mode-line-decor-window-dedicated
 
                       wg-mode-line-decor-window-undedicated)
 
                     (wg-add-face :div wg-mode-line-decor-divider)
 
                     (if (wg-session-modified (wg-current-session))
 
                         wg-mode-line-decor-session-modified
 
                       wg-mode-line-decor-session-unmodified)
 
                     (if (wg-workgroup-modified wg)
 
                         wg-mode-line-decor-workgroup-modified
 
                       wg-mode-line-decor-workgroup-unmodified)))
 
                (:brace wg-mode-line-decor-right-brace)))
 
          (t (if wg-display-nowg
 
                 (progn
 
                   (wg-fontify " "
 
                     (:brace wg-mode-line-decor-left-brace)
 
                     (:mode wg-nowg-string)
 
                     (:brace wg-mode-line-decor-right-brace)))
 
               "")))))
 

	
 
(defun wg-change-modeline ()
 
  "Add Workgroups' mode-line format to `mode-line-format'."
 
  (unless (or (assq 'wg-mode-line-display-on mode-line-format)
 
              wg-mode-line-disable)
 
    (let ((format '(wg-mode-line-display-on (:eval (wg-mode-line-string))))
 
          (pos (or (cl-position 'mode-line-position mode-line-format) 10)))
 
      (set-default 'mode-line-format
 
                   (wg-insert-after format mode-line-format pos))
 
      (force-mode-line-update))))
 

	
 

	
 
(defun wg-remove-mode-line-display ()
 
  "Remove Workgroups' mode-line format from `mode-line-format'."
 
  (wg-awhen (assq 'wg-mode-line-display-on mode-line-format)
 
    (set-default 'mode-line-format (remove it mode-line-format))
 
    (force-mode-line-update)))
 

	
 

	
 
(defun wg-toggle-mode-line-display ()
 
  "Toggle `wg-mode-line-display-on'."
 
  (interactive)
 
  (wg-toggle-and-message 'wg-mode-line-display-on))
 

	
 
(defun wg-add-workgroups-mode-minor-mode-entries ()
 
  "Add Workgroups' minor-mode entries.
 
Adds entries to `minor-mode-list', `minor-mode-alist' and
 
`minor-mode-map-alist'."
 
  (cl-pushnew 'workgroups-mode minor-mode-list)
 
  (cl-pushnew '(workgroups-mode wg-modeline-string) minor-mode-alist :test 'equal)
 
  (setq minor-mode-map-alist
 
        (cons (cons 'workgroups-mode (wg-make-workgroups-mode-map))
 
              (delete (assoc 'workgroups-mode minor-mode-map-alist)
 
                      minor-mode-map-alist))))
 

	
 

	
 
(provide 'workgroups-modeline)
 
;;; workgroups-modeline.el ends here
src/workgroups-pickel.el
Show inline comments
 
;;; workgroups-pickel.el --- Elisp object serdes used by Workgroups
 
;;; Commentary:
 
;;
 
;; Copyright (C) 2010, 2011 tlh
 
;; Workgroups allows you to serialize some objects, even such as buffers
 
;; (that are displayed as #<object>). The only trick is to write
 
;; functions that extract enough information about an object and
 
;; functions that can recreate an object.
 
;;
 
;; Author: tlh <thunkout at gmail dot com>
 
;; Keywords: serialization deserialization serdes
 
;; Homepage: https://github.com/tlh/workgroups.el
 
;; 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 2 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, write to the Free Software
 
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
;; USA
 

	
 
;;; Commentary:
 
;; Main functions are: `wg-pickel', `wg-pickel-to-string', `wg-pickel-to-file'
 
;; What objects are supported? See `wg-pickel-pickelable-types'
 
;;
 
;;; Code:
 

	
 
(require 'cl-lib)
 
(require 'workgroups-utils-basic)
 

	
 

	
 
;;; vars
 

	
 
(defvar wg-pickel-identifier '~pickel!~
 
  "Symbol identifying a stream as a pickel.")
 

	
 
(defvar wg-pickel-pickelable-types
 
  '(integer
 
    float
 
    symbol
 
    string
 
    cons
 
    vector
 
    hash-table
 
    buffer
 
    marker
 
    ;;window-configuration
 
    ;;frame
 
    ;;window
 
    ;;process
 
    )
 
  "Types pickel can serialize.")
 
@@ -56,31 +39,33 @@
 
    (float      . identity)
 
    (string     . identity)
 
    (symbol     . wg-pickel-symbol-serializer)
 
    (cons       . wg-pickel-cons-serializer)
 
    (vector     . wg-pickel-vector-serializer)
 
    (hash-table . wg-pickel-hash-table-serializer)
 
    (buffer     . wg-pickel-buffer-serializer)
 
    (marker     . wg-pickel-marker-serializer)
 
    ;;(window-configuration   . wg-pickel-window-configuration-serializer)
 
    (buffer     . wg-pickel-buffer-serializer))
 
    )
 
  "Alist mapping types to object serialization functions.")
 

	
 
(defvar wg-pickel-link-serializers
 
  '((cons       . wg-pickel-cons-link-serializer)
 
    (vector     . wg-pickel-vector-link-serializer)
 
    (hash-table . wg-pickel-hash-table-link-serializer))
 
  "Alist mapping types to link serialization functions.")
 

	
 
(defvar wg-pickel-object-deserializers
 
  '((s . wg-pickel-deserialize-uninterned-symbol)
 
    (c . wg-pickel-deserialize-cons)
 
    (v . wg-pickel-deserialize-vector)
 
    (h . wg-pickel-deserialize-hash-table)
 
    (b . wg-pickel-deserialize-buffer))
 
  ;; (f . wg-pickel-deserialize-frame))
 
    (b . wg-pickel-deserialize-buffer)
 
    (m . wg-pickel-deserialize-marker)
 
    ;;(f . wg-pickel-deserialize-frame)
 
    )
 
  "Alist mapping type keys to object deserialization functions.")
 

	
 
(defvar wg-pickel-link-serializers
 
  '((cons       . wg-pickel-cons-link-serializer)
 
    (vector     . wg-pickel-vector-link-serializer)
 
    (hash-table . wg-pickel-hash-table-link-serializer))
 
  "Alist mapping types to link serialization functions.")
 
(defvar wg-pickel-link-deserializers
 
  `((c . wg-pickel-cons-link-deserializer)
 
    (v . wg-pickel-vector-link-deserializer)
 
    (h . wg-pickel-hash-table-link-deserializer))
 
  "Alist mapping type keys to link deserialization functions.")
 

	
 
@@ -169,150 +154,162 @@
 
                   (inner val)))))))
 
      (inner obj)
 
      binds)))
 

	
 

	
 

	
 
;;; object serialization
 
;;; Objects
 

	
 
;; symbol
 
;; (wg-unpickel (wg-pickel 123))
 
;; (wg-unpickel (wg-pickel "table"))
 
;; (wg-unpickel (wg-pickel 'test))
 
(defun wg-pickel-symbol-serializer (symbol)
 
  "Return SYMBOL's serialization."
 
  (cond ((eq symbol t) t)
 
        ((eq symbol nil) nil)
 
        ((intern-soft symbol) symbol)
 
        (t (list 's (symbol-name symbol)))))
 
(defun wg-pickel-deserialize-uninterned-symbol (name)
 
  "Return a new uninterned symbol from NAME."
 
  (make-symbol name))
 

	
 
(defun wg-pickel-cons-serializer (cons)
 
  "Return CONS's serialization."
 
  (list 'c))
 

	
 
(defun wg-pickel-vector-serializer (vector)
 
  "Return VECTOR's serialization."
 
  (list 'v (length vector)))
 

	
 
(defun wg-pickel-hash-table-serializer (table)
 
  "Return HASH-TABLE's serialization."
 
  (list 'h
 
        (hash-table-test table)
 
        (hash-table-size table)
 
        (hash-table-rehash-size table)
 
        (hash-table-rehash-threshold table)
 
        (hash-table-weakness table)))
 

	
 
(defun wg-pickel-window-configuration-serializer (wc)
 
  "Return Window configuration WC's serialization."
 
  (list 'wc
 
        1))
 

	
 
;; buffer
 
;; (wg-unpickel (wg-pickel (current-buffer)))
 
(defun wg-pickel-buffer-serializer (buffer)
 
  "Return BUFFER's UID in workgroups buffer list."
 
  (list 'b (wg-add-buffer-to-buf-list buffer)))
 

	
 
(defun wg-pickel-serialize-objects (binds)
 
  "Return a list of serializations of the objects in BINDS."
 
  (let (result)
 
    (wg-dohash (obj id binds result)
 
      (setq result
 
            (nconc (list id (funcall (wg-pickel-object-serializer obj) obj))
 
                   result)))))
 
(defun wg-pickel-deserialize-buffer (uid)
 
  "Return a restored buffer from it's UID."
 
  (save-window-excursion
 
    (wg-restore-buffer (wg-find-buf-by-uid uid))))
 

	
 

	
 
;; marker
 
;; (wg-unpickel (wg-pickel (point-marker)))
 
(defun wg-pickel-marker-serializer (marker)
 
  "Return MARKERS's data."
 
  (list 'm (list (marker-position marker)
 
                 (wg-add-buffer-to-buf-list (marker-buffer marker)))))
 
(defun wg-pickel-deserialize-marker (data)
 
  "Return marker from it's data."
 
  (let ((m (make-marker)))
 
    (set-marker m (car data) (wg-pickel-deserialize-buffer (car (cdr data))))))
 

	
 
;;; link serialization
 

	
 
;; cons - http://www.gnu.org/software/emacs/manual/html_node/eintr/cons.html
 
(defun wg-pickel-cons-serializer (cons)
 
  "Return CONS's serialization."
 
  (list 'c))
 
(defun wg-pickel-deserialize-cons ()
 
  "Return a new cons cell initialized to nil."
 
  (cons nil nil))
 
(defun wg-pickel-cons-link-serializer (cons binds)
 
  "Return the serialization of CONS's links in BINDS."
 
  (list 'c
 
        (gethash cons binds)
 
        (gethash (car cons) binds)
 
        (gethash (cdr cons) binds)))
 
(defun wg-pickel-cons-link-deserializer (cons-id car-id cdr-id binds)
 
  "Relink a cons cell with its car and cdr in BINDS."
 
  (let ((cons (gethash cons-id binds)))
 
    (setcar cons (gethash car-id binds))
 
    (setcdr cons (gethash cdr-id binds))))
 

	
 

	
 

	
 
;; vector - http://www.gnu.org/software/emacs/manual/html_node/elisp/Vector-Functions.html
 
;; (wg-unpickel (wg-pickel (make-vector 9 'Z)))
 
;;
 
(defun wg-pickel-vector-serializer (vector)
 
  "Return VECTOR's serialization."
 
  (list 'v (length vector)))
 
(defun wg-pickel-deserialize-vector (length)
 
  "Return a new vector of length LENGTH."
 
  (make-vector length nil))
 
(defun wg-pickel-vector-link-serializer (vector binds)
 
  "Return the serialization of VECTOR's links in BINDS."
 
  (let (result)
 
    (dotimes (i (length vector) result)
 
      (setq result
 
            (nconc (list 'v
 
                         (gethash vector binds)
 
                         i
 
                         (gethash (aref vector i) binds))
 
                   result)))))
 
(defun wg-pickel-vector-link-deserializer (vector-id index value-id binds)
 
  "Relink a vector with its elements in BINDS."
 
  (aset (gethash vector-id binds) index (gethash value-id binds)))
 

	
 

	
 
;; hash table - http://www.gnu.org/software/emacs/manual/html_node/elisp/Hash-Tables.html
 
(defun wg-pickel-hash-table-serializer (table)
 
  "Return HASH-TABLE's serialization."
 
  (list 'h
 
        (hash-table-test table)
 
        (hash-table-size table)
 
        (hash-table-rehash-size table)
 
        (hash-table-rehash-threshold table)
 
        (hash-table-weakness table)))
 
(defun wg-pickel-deserialize-hash-table (test size rsize rthresh weakness)
 
  "Return a new hash-table with the specified properties."
 
  (make-hash-table :test test :size size :rehash-size rsize
 
                   :rehash-threshold rthresh :weakness weakness))
 
(defun wg-pickel-hash-table-link-serializer (table binds)
 
  "Return the serialization of TABLE's links in BINDS."
 
  (let (result)
 
    (wg-dohash (key value table result)
 
      (setq result
 
            (nconc (list 'h
 
                         (gethash key binds)
 
                         (gethash value binds)
 
                         (gethash table binds))
 
                   result)))))
 

	
 
(defun wg-pickel-serialize-links (binds)
 
  "Return a list of serializations of the links between objects in BINDS."
 
  (let (result)
 
    (wg-dohash (obj id binds result)
 
      (wg-awhen (wg-pickel-link-serializer obj)
 
        (setq result (nconc (funcall it obj binds) result))))))
 

	
 
(defun wg-pickel-hash-table-link-deserializer (key-id value-id table-id binds)
 
  "Relink a hash-table with its keys and values in BINDS."
 
  (puthash (gethash key-id binds)
 
           (gethash value-id binds)
 
           (gethash table-id binds)))
 

	
 

	
 
;;; object deserialization
 

	
 
(defun wg-pickel-deserialize-uninterned-symbol (name)
 
  "Return a new uninterned symbol from NAME."
 
  (make-symbol name))
 
;; TODO
 
(defun wg-pickel-window-configuration-serializer (wc)
 
  "Return Window configuration WC's serialization."
 
  (list 'wc 1))
 

	
 
(defun wg-pickel-deserialize-cons ()
 
  "Return a new cons cell initialized to nil."
 
  (cons nil nil))
 

	
 
(defun wg-pickel-deserialize-vector (length)
 
  "Return a new vector of length LENGTH."
 
  (make-vector length nil))
 

	
 
(defun wg-pickel-deserialize-hash-table (test size rsize rthresh weakness)
 
  "Return a new hash-table with the specified properties."
 
  (make-hash-table :test test :size size :rehash-size rsize
 
                   :rehash-threshold rthresh :weakness weakness))
 

	
 
(defun wg-pickel-deserialize-buffer (uid)
 
  "Return a restored buffer from it's UID."
 
  (wg-restore-buffer (wg-find-buf-by-uid uid)))
 

	
 
(defun wg-pickel-serialize-objects (binds)
 
  "Return a list of serializations of the objects in BINDS."
 
  (let (result)
 
    (wg-dohash (obj id binds result)
 
      (setq result
 
            (nconc (list id (funcall (wg-pickel-object-serializer obj) obj))
 
                   result)))))
 
(defun wg-pickel-deserialize-objects (serial-objects)
 
  "Return a hash-table of objects deserialized from SERIAL-OBJECTS."
 
  (let ((binds (make-hash-table)))
 
    (wg-destructuring-dolist ((id obj . rest) serial-objects binds)
 
      (puthash id
 
               (if (atom obj) obj
 
                 (wg-dbind (key . data) obj
 
                   (apply (wg-pickel-object-deserializer key) data)))
 
               binds))))
 

	
 

	
 

	
 
;;; link deserialization
 

	
 
(defun wg-pickel-cons-link-deserializer (cons-id car-id cdr-id binds)
 
  "Relink a cons cell with its car and cdr in BINDS."
 
  (let ((cons (gethash cons-id binds)))
 
    (setcar cons (gethash car-id binds))
 
    (setcdr cons (gethash cdr-id binds))))
 

	
 
(defun wg-pickel-vector-link-deserializer (vector-id index value-id binds)
 
  "Relink a vector with its elements in BINDS."
 
  (aset (gethash vector-id binds) index (gethash value-id binds)))
 

	
 
(defun wg-pickel-hash-table-link-deserializer (key-id value-id table-id binds)
 
  "Relink a hash-table with its keys and values in BINDS."
 
  (puthash (gethash key-id binds)
 
           (gethash value-id binds)
 
           (gethash table-id binds)))
 

	
 
(defun wg-pickel-serialize-links (binds)
 
  "Return a list of serializations of the links between objects in BINDS."
 
  (let (result)
 
    (wg-dohash (obj id binds result)
 
      (wg-awhen (wg-pickel-link-serializer obj)
 
        (setq result (nconc (funcall it obj binds) result))))))
 
(defun wg-pickel-deserialize-links (serial-links binds)
 
  "Return BINDS after relinking all its objects according to SERIAL-LINKS."
 
  (wg-destructuring-dolist ((key arg1 arg2 arg3 . rest) serial-links binds)
 
    (funcall (wg-pickel-link-deserializer key) arg1 arg2 arg3 binds)))
 

	
 

	
 
@@ -356,52 +353,8 @@
 
  (wg-unpickel (wg-lisp-object-from-file file)))
 

	
 
(defun wg-unpickel-string (str)
 
  "`unpickel' and object directly from STR."
 
  (wg-unpickel (read str)))
 

	
 

	
 

	
 

	
 

	
 
;;; parameter pickeling
 

	
 
  (defun wg-pickel-workgroup-parameters (workgroup)
 
    "If WORKGROUP's parameters are non-nil, return a copy of
 
WORKGROUP after pickeling its parameters. Otherwise return
 
WORKGROUP."
 
    (if (not (wg-workgroup-parameters workgroup)) workgroup
 
      (let ((copy (wg-copy-workgroup workgroup)))
 
        (wg-asetf (wg-workgroup-parameters copy) (wg-pickel it))
 
        copy)))
 

	
 
  (defun wg-unpickel-workgroup-parameters (workgroup)
 
    "If WORKGROUP's parameters are non-nil, return a copy of
 
WORKGROUP after unpickeling its parameters. Otherwise return
 
WORKGROUP."
 
    (if (not (wg-workgroup-parameters workgroup)) workgroup
 
      (let ((copy (wg-copy-workgroup workgroup)))
 
        (wg-asetf (wg-workgroup-parameters copy) (wg-unpickel it))
 
        copy)))
 

	
 
  (defun wg-pickel-all-session-parameters (session)
 
    "Return a copy of SESSION after pickeling its
 
parameters and the parameters of all its workgroups."
 
    (let ((copy (wg-copy-session session)))
 
      (when (wg-session-parameters copy)
 
        (wg-asetf (wg-session-parameters copy) (wg-pickel it)))
 
      (wg-asetf (wg-session-workgroup-list copy)
 
                (cl-mapcar 'wg-pickel-workgroup-parameters it))
 
      copy))
 

	
 
  (defun wg-unpickel-session-parameters (session)
 
    "Return a copy of SESSION after unpickeling its
 
parameters and the parameters of all its workgroups."
 
    (let ((copy (wg-copy-session session)))
 
      (when (wg-session-parameters copy)
 
        (wg-asetf (wg-session-parameters copy) (wg-unpickel it)))
 
      (wg-asetf (wg-session-workgroup-list copy)
 
                (cl-mapcar 'wg-unpickel-workgroup-parameters it))
 
      copy))
 

	
 
(provide 'workgroups-pickel)
 
;;; workgroups-pickel.el ends here
src/workgroups-restore.el
Show inline comments
 
deleted file
src/workgroups-session.el
Show inline comments
 
new file 100644
 
;;; workgroups-session.el --- Top level structure "session"
 
;;; Commentary:
 
;; Main function are: `wg-write-session-file'
 
;;; Code:
 

	
 
(require 'workgroups-variables)
 
(require 'workgroups-workgroup)
 

	
 

	
 

	
 
;;
 
;; Variables
 
;;
 

	
 
(defcustom wg-session-load-on-start (not (daemonp))
 
  "Load a session file on Workgroups start.
 
But only if Emacs is not started as daemon.  You don't want any
 
promts while Emacs is being started as daemon."
 
  :type 'boolean
 
  :group 'workgroups)
 
(defvaralias 'wg-use-default-session-file 'wg-session-load-on-start)
 

	
 
(defcustom wg-session-file
 
  "~/.emacs_workgroups"
 
  "Default filename to be used to save workgroups."
 
  :type 'file
 
  :group 'workgroups)
 
(defvaralias 'wg-default-session-file 'wg-session-file)
 

	
 
(defvar wg-deactivation-list nil
 
  "A stack of workgroups that are currently being switched away from.
 
Used to avoid associating the old workgroup's buffers with the
 
new workgroup during a switch.")
 

	
 
(defvar wg-incorrectly-restored-bufs nil
 
  "FIXME: docstring this.")
 
;; TODO: check it on switching WG
 

	
 
(defvar wg-record-incorrectly-restored-bufs nil
 
  "FIXME: docstring this.")
 

	
 
(defcustom wg-emacs-exit-save-behavior 'save
 
  "Determines save behavior on Emacs exit.
 
Possible values:
 

	
 
`ask'           Ask the user whether to save if there are unsaved changes
 

	
 
`save'          Call `wg-save-session' when there are unsaved changes
 

	
 
Anything else   Exit Emacs without saving changes"
 
  :type 'symbol
 
  :group 'workgroups)
 

	
 
(defcustom wg-workgroups-mode-exit-save-behavior 'save
 
  "Determines save behavior on `workgroups-mode' exit.
 
Possible values:
 

	
 
`ask'           Ask the user whether to saveif there are unsaved changes
 

	
 
`save'          Call `wg-save-session' when there are unsaved changes
 

	
 
Anything else   Exit `workgroups-mode' without saving changes"
 
  :type 'symbol
 
  :group 'workgroups)
 

	
 

	
 

	
 
;;
 
;; Function
 
;;
 

	
 
(defun wg-session-uids-consistent-p ()
 
  "Return t if there are no duplicate bufs or buf uids in the wrong places.
 
nil otherwise."
 
  (and (not (wg-dups-p (wg-buf-list) :key 'wg-buf-uid :test 'string=))
 
       (not (wg-dups-p (wg-workgroup-list) :key 'wg-workgroup-uid :test 'string=))))
 

	
 

	
 
(defun wg-find-session-file (filename)
 
  "Load a session visiting FILENAME, creating one if none already exists."
 
  (interactive "FFind session file: ")
 
  (cond ((file-exists-p filename)
 
         (let ((session (wg-read-sexp-from-file filename)))
 
           (unless (wg-session-p session)
 
             (error "%S is not a Workgroups session file." filename))
 
           (setf (wg-session-file-name session) filename)
 
           (wg-reset-internal (wg-unpickel-session-parameters session)))
 
         (wg-awhen (and wg-switch-to-first-workgroup-on-find-session-file
 
                        (wg-workgroup-list))
 
           (if (and wg-open-this-wg
 
                    (member wg-open-this-wg (wg-workgroup-names)))
 
               (wg-switch-to-workgroup wg-open-this-wg)
 
             (if (and wg-load-last-workgroup
 
                      (member (wg-session-parameter (wg-current-session t) 'last-workgroup)
 
                              (wg-workgroup-names)))
 
                 (wg-switch-to-workgroup
 
                  (wg-session-parameter (wg-current-session t) 'last-workgroup))
 
               (wg-switch-to-workgroup (car it)))
 
             ))
 
         (if wg-control-frames
 
             (wg-restore-frames))
 
         (wg-fontified-message (:cmd "Loaded: ") (:file filename)))
 
        (t
 
         (wg-query-and-save-if-modified)
 
         (wg-reset-internal (wg-make-session :file-name filename))
 
         (wg-fontified-message
 
           (:cmd "(New Workgroups session file)")))))
 
(defalias 'wg-open-session 'wg-find-session-file)
 

	
 
(defun wg-write-session-file (filename &optional confirm)
 
  "Write the current session into file FILENAME.
 
This makes the session visit that file, and marks it as not modified.
 

	
 
If optional second arg CONFIRM is non-nil, this function asks for
 
confirmation before overwriting an existing file.  Interactively,
 
confirmation is required unless you supply a prefix argument.
 

	
 
Think of it as `write-file' for Workgroups sessions."
 
  (interactive (list (read-file-name "Save session as: ")
 
                     (not current-prefix-arg)))
 
  (when (and confirm (file-exists-p filename))
 
    (unless (y-or-n-p (format "File `%s' exists; overwrite? " filename))
 
      (error "Cancelled")))
 
  (unless (file-writable-p filename)
 
    (error "File %s can't be written to" filename))
 
  (wg-perform-session-maintenance)
 
  (setf (wg-session-file-name (wg-current-session)) filename)
 
  (setf (wg-session-version (wg-current-session)) wg-version)
 
  (if wg-control-frames
 
      (wg-save-frames))
 
  (wg-write-sexp-to-file
 
   (wg-pickel-all-session-parameters (wg-current-session))
 
   filename)
 
  (wg-mark-everything-unmodified)
 
  (wg-fontified-message (:cmd "Wrote: ") (:file filename)))
 
(defalias 'wg-save-session-as 'wg-write-session-file)
 

	
 
(defun wg-determine-session-save-file-name ()
 
  "Return the filename in which to save the session."
 
  (or (wg-session-file-name (wg-current-session))
 
      (and wg-session-load-on-start wg-session-file)))
 

	
 
(defun wg-save-session (&optional force)
 
  "Save the current Workgroups session if it's been modified.
 
Think of it as `save-buffer' for Workgroups sessions.  Optional
 
argument FORCE non-nil, or interactively with a prefix arg, save
 
the session regardless of whether it's been modified."
 
  (interactive "P")
 
  (if (and (not (wg-modified-p)) (not force))
 
      (wg-message "(The session is unmodified)")
 
    (wg-write-session-file
 
     (or (wg-determine-session-save-file-name)
 
         (read-file-name "Save session as: ")))))
 

	
 
(defun wg-reset-internal (&optional session)
 
  "Reset Workgroups, setting `wg-current-session' to SESSION.
 
Resets all frame parameters, buffer-local vars, current
 
Workgroups session object, etc.  SESSION nil defaults to a new,
 
blank session object."
 
  (mapc 'wg-reset-frame (frame-list))
 
  (mapc 'wg-reset-buffer (buffer-list))
 
  (setq wg-wconfig-kill-ring nil)
 
  (setq wg-current-session (or session (wg-make-session))))
 

	
 

	
 

	
 
(defun wg-session-all-buf-uids (&optional session)
 
  "Return a new list of all unique buf uids in SESSION.
 
SESSION nil defaults to `wg-current-session'."
 
  (cl-reduce 'wg-string-list-union
 
             (wg-session-workgroup-list (or session (wg-current-session)))
 
             :key 'wg-workgroup-all-buf-uids))
 

	
 
(defun wg-buffer-list-all-uids (&optional buffer-list)
 
  "Return a list of the uids of all buffers in BUFFER-LIST in
 
which `wg-buffer-uid' is locally bound.
 
BUFFER-LIST nil defaults to `buffer-list'."
 
  (delq nil (mapcar 'wg-buffer-uid (or buffer-list (buffer-list)))))
 

	
 
(defun wg-all-buf-uids (&optional session buffer-list)
 
  "Return the union of `wg-session-all-buf-uids' and `wg-buffer-list-all-uids'."
 
  (cl-union (wg-session-all-buf-uids session)
 
            (wg-buffer-list-all-uids buffer-list)
 
            :test 'string=))
 

	
 
(defun wg-gc-bufs ()
 
  "gc bufs from `wg-buf-list' that are no longer needed."
 
  (let ((all-buf-uids (wg-all-buf-uids)))
 
    (wg-asetf (wg-buf-list)
 
              (cl-remove-if-not (lambda (uid) (member uid all-buf-uids)) it
 
                                :key 'wg-buf-uid))))
 

	
 

	
 

	
 
;; FIXME: Duplicate buf names probably shouldn't be allowed.  An unrelated error
 
;; causes two *scratch* buffers to be present, triggering the "uids don't match"
 
;; error.  Write something to remove bufs with duplicate names.
 

	
 

	
 
(defun wg-perform-session-maintenance ()
 
  "Perform various maintenance operations on the current Workgroups session."
 
  (wg-update-current-workgroup-working-wconfig)
 

	
 
  ;; Update every workgroup's base wconfig with `wg-workgroup-update-base-wconfig'
 
  (dolist (workgroup (wg-workgroup-list))
 
    (wg-awhen (wg-workgroup-selected-frame-wconfig workgroup)
 
      (setf (wg-workgroup-base-wconfig workgroup) it
 
            (wg-workgroup-selected-frame-wconfig workgroup) nil)))
 

	
 
  (wg-gc-bufs)
 
  (wg-gc-buf-uids)
 
  (wg-update-buf-list))
 

	
 

	
 
;; session consistency testing
 

	
 

	
 
(defun wg-modified-p ()
 
  "Return t when the current session or any of its workgroups are modified."
 
  (or (wg-session-modified (wg-current-session))
 
      (cl-some 'wg-workgroup-modified (wg-workgroup-list))))
 

	
 
(defun wg-mark-everything-unmodified ()
 
  "Mark the session and all workgroups as unmodified."
 
  (setf (wg-session-modified (wg-current-session)) nil)
 
  (dolist (workgroup (wg-workgroup-list))
 
    (setf (wg-workgroup-modified workgroup) nil)))
 

	
 

	
 
(defun wg-workgroup-names (&optional noerror)
 
  "Return a list of workgroup names or scream unless NOERROR."
 
  (mapcar 'wg-workgroup-name (wg-workgroup-list-or-error noerror)))
 

	
 

	
 
;;; session parameters
 

	
 
(defun wg-session-parameter (session parameter &optional default)
 
  "Return SESSION's value for PARAMETER.
 
If PARAMETER is not found, return DEFAULT which defaults to nil.
 
SESSION nil defaults to the current session."
 
  (wg-aget (wg-session-parameters (or session (wg-current-session)))
 
           parameter default))
 

	
 
(defun wg-set-session-parameter (session parameter value)
 
  "Set SESSION's value of PARAMETER to VALUE.
 
SESSION nil means use the current session.
 
Return value."
 
  (let ((session (or session (wg-current-session))))
 
    (wg-set-parameter (wg-session-parameters session) parameter value)
 
    (setf (wg-session-modified session) t)
 
    value))
 

	
 
(defun wg-remove-session-parameter (session parameter)
 
  "Remove parameter PARAMETER from SESSION's parameters."
 
  (let ((session (or session (wg-current-session))))
 
    (wg-asetf (wg-session-parameters session) (wg-aremove it parameter))
 
    (setf (wg-session-modified session) t)))
 

	
 
(defun wg-session-local-value (variable &optional session)
 
  "Return the value of VARIABLE in SESSION.
 
SESSION nil defaults to the current session.  If VARIABLE does
 
not have a session-local binding in SESSION, the value is
 
resolved by Emacs."
 
  (let* ((undefined (cl-gensym))
 
         (value (wg-session-parameter session variable undefined)))
 
    (if (not (eq value undefined)) value
 
      (symbol-value variable))))
 

	
 

	
 
(defun wg-reset-frame (frame)
 
  "Reset Workgroups' frame-parameters in FRAME to nil."
 
  (set-frame-parameter frame 'wg-workgroup-state-table nil)
 
  (set-frame-parameter frame 'wg-current-workgroup-uid nil)
 
  (set-frame-parameter frame 'wg-previous-workgroup-uid nil))
 

	
 

	
 

	
 
(defun wg-save-session-on-exit (behavior)
 
  "Perform session-saving operations based on BEHAVIOR."
 
  (cl-case behavior
 
    (ask (wg-query-and-save-if-modified))
 
    (save
 
     (if (wg-determine-session-save-file-name)
 
         (wg-save-session)
 
       (wg-query-and-save-if-modified)))))
 

	
 
(defun wg-save-frames ()
 
  "Save opened frames as a session parameter.
 
Exclude `selected-frame' and daemon one (if any).
 
http://stackoverflow.com/questions/21151992/why-emacs-as-daemon-gives-1-more-frame-than-is-opened"
 
  (interactive)
 
  (let ((fl (frame-list)))
 
    (mapc (lambda (frame)
 
            (if (string-equal "initial_terminal" (terminal-name frame))
 
                (delete frame fl))) fl)
 
    (setq fl (delete (selected-frame) fl))
 
    (if (wg-current-session t)
 
        (wg-set-session-parameter (wg-current-session t)
 
                                  'frame-list
 
                                  (mapcar 'wg-frame-to-wconfig fl)))))
 

	
 

	
 
(defun wg-reload-session ()
 
  "Reload current workgroups session."
 
  (interactive)
 
  (let ((file (or (wg-determine-session-save-file-name)
 
                  wg-session-file)))
 
    (when (file-exists-p file)
 
      (condition-case err
 
          (wg-open-session wg-session-file)
 
        (progn
 
          (wg-create-first-wg)
 
          (error (message "Error finding session-file: %s" err)))))
 
    (wg-create-first-wg)))
 

	
 
(defun wg-save-session-on-emacs-exit ()
 
  "Call `wg-save-session-on-exit' with `wg-emacs-exit-save-behavior'.
 
Added to `kill-emacs-query-functions'."
 
  (wg-save-session-on-exit wg-emacs-exit-save-behavior) t)
 

	
 
(defun wg-save-session-on-workgroups-mode-exit ()
 
  "Call `wg-save-session-on-exit' with `wg-workgroups-mode-exit-save-behavior'.
 
Called when `workgroups-mode' is turned off."
 
  (wg-save-session-on-exit wg-workgroups-mode-exit-save-behavior) t)
 

	
 

	
 
(defun wg-pickel-all-session-parameters (session)
 
  "Return a copy of SESSION after pickeling its
 
parameters and the parameters of all its workgroups."
 
  (let ((copy (wg-copy-session session)))
 
    (when (wg-session-parameters copy)
 
      (wg-asetf (wg-session-parameters copy) (wg-pickel it)))
 
    (wg-asetf (wg-session-workgroup-list copy)
 
              (cl-mapcar 'wg-pickel-workgroup-parameters it))
 
    copy))
 

	
 
(defun wg-unpickel-session-parameters (session)
 
  "Return a copy of SESSION after unpickeling its
 
parameters and the parameters of all its workgroups."
 
  (let ((copy (wg-copy-session session)))
 
    (when (wg-session-parameters copy)
 
      (wg-asetf (wg-session-parameters copy) (wg-unpickel it)))
 
    (wg-asetf (wg-session-workgroup-list copy)
 
              (cl-mapcar 'wg-unpickel-workgroup-parameters it))
 
    copy))
 

	
 

	
 
(provide 'workgroups-session)
 
;;; workgroups-session.el ends here
src/workgroups-specialbufs.el
Show inline comments
 
@@ -5,13 +5,44 @@
 
;;  1. Add more special buffers support (that you use)
 
;;  2. Improve existing
 
;;
 
;;; Code:
 

	
 
(require 'workgroups-variables)
 
(require 'workgroups-support-macro)
 

	
 
(defcustom wg-special-buffer-serdes-functions
 
  '(wg-serialize-comint-buffer
 
    wg-serialize-speedbar-buffer)
 
  "Functions providing serialization/deserialization for complex buffers.
 

	
 
Use `wg-support' macro and this variable will be filled
 
automatically.
 

	
 
An entry should be either a function symbol or a lambda, and should
 
accept a single Emacs buffer object as an argument.
 

	
 
When a buffer is to be serialized, it is passed to each of these
 
functions in turn until one returns non-nil, or the list ends.  A
 
return value of nil indicates that the function can't handle
 
buffers of that type.  A non-nil return value indicates that it
 
can.  The first non-nil return value becomes the buffer's special
 
serialization data.  The return value should be a cons, with a
 
deserialization function (a function symbol or a lambda) as the car,
 
and any other serialization data as the cdr.
 

	
 
When it comes time to deserialize the buffer, the deserialization
 
function (the car of the cons mentioned above) is passed the
 
wg-buf object, from which it should restore the buffer.  The
 
special serialization data itself can be accessed
 
with (cdr (wg-buf-special-data <wg-buf>)).  The deserialization
 
function must return the restored Emacs buffer object.
 

	
 
See the definitions of the functions in this list for examples of
 
how to write your own."
 
  :type 'alist
 
  :group 'workgroups)
 

	
 
;; Dired
 
(wg-support 'dired-mode 'dired
 
            `((deserialize . ,(lambda (buffer vars)
 
                                (if (or wg-restore-remote-buffers
 
                                        (not (file-remote-p default-directory)))
 
@@ -173,14 +204,15 @@ You can get these commands using `wg-get-org-agenda-view-commands'."
 

	
 
;; ensime-inf
 
(wg-support 'ensime-inf-mode 'ensime
 
            `((deserialize . ,(lambda (buffer vars)
 
                                (save-window-excursion
 
                                  (ensime-inf-switch))
 
                                (switch-to-buffer ensime-inf-buffer-name)
 
                                (goto-char (point-max))))))
 
                                (when (boundp 'ensime-inf-buffer-name)
 
                                  (switch-to-buffer ensime-inf-buffer-name)
 
                                  (goto-char (point-max)))))))
 

	
 
;; compilation-mode
 
;;
 
;; I think it's not a good idea to compile a program just to switch
 
;; workgroups. So just restoring a buffer name.
 
(wg-support 'compilation-mode 'compile
 
@@ -244,13 +276,13 @@ You can get these commands using `wg-get-org-agenda-view-commands'."
 
(defun wg-serialize-speedbar-buffer (buffer)
 
  "Serialize speedbar BUFFER."
 
  (with-current-buffer buffer
 
    (if (fboundp 'speedbar-mode)
 
        (when (eq major-mode 'speedbar-mode)
 
          (list 'wg-deserialize-speedbar-buffer
 
                (wg-take-until-unreadable (list default-directory))
 
                (list default-directory)
 
                )))))
 

	
 

	
 
(defun wg-deserialize-slime-buffer (buf)
 
  "Deserialize `slime' buffer BUF."
 
  (when (require 'slime nil 'noerror)
 
@@ -278,14 +310,13 @@ You can get these commands using `wg-get-org-agenda-view-commands'."
 
    (if (fboundp 'comint-mode)
 
        (when (eq major-mode 'comint-mode)
 
          ;; `slime-inferior-lisp-args' var is used when in `slime'
 
          (when (and (boundp 'slime-inferior-lisp-args)
 
                     slime-inferior-lisp-args)
 
            (list 'wg-deserialize-slime-buffer
 
                  (wg-take-until-unreadable (list default-directory
 
                                                  slime-inferior-lisp-args))
 
                  (list default-directory slime-inferior-lisp-args)
 
                ))))))
 

	
 
;; inf-mongo
 
;; https://github.com/tobiassvn/inf-mongo
 
;; `mongo-command' - command used to start inferior mongo
 
(wg-support 'inf-mongo-mode 'inf-mongo
src/workgroups-structs.el
Show inline comments
 
;;; workgroups-structs.el --- Data structures for WG
 
;;; workgroups-structs.el --- Define Elisp objects
 
;;; Commentary:
 
;;
 
;; `wg-defstruct' - it creates functions named like "wg-buf-...",
 
;; "wg-session-...", "wg-make-win" and so on (to manipulate the
 
;; structures)
 
;;
 
;; So if you have "(wg-defstruct wg session ...)" - then you have
 
;; `wg-session-file-name' and other defined fields.
 
;;
 
;; To get a value you can use:
 
;;   (wg-session-... (wg-current-session))
 
;;
 
;; Example:
 
;;   (wg-session-file-name (wg-current-session))
 
;;   (wg-workgroup-parameters (wg-current-workgroup))
 
;;
 
;; To set a value (code used in `wg-write-session-file'):
 
;;   (setf (wg-session-file-name (wg-current-session)) filename)
 
;;
 
;;; Code:
 

	
 
(require 'workgroups-utils-basic)
 

	
 
(wg-defstruct wg buf
 
(wg-defstruct wg session
 
  (uid (wg-generate-uid))
 
  (name)
 
  (modified)
 
  (parameters)
 
  (file-name)
 
  (point)
 
  (mark)
 
  (local-vars)
 
  (special-data)
 
  ;; This may be used later:
 
  (gc))
 
  (version wg-version)
 
  (workgroup-list)
 
  (buf-list))
 

	
 
(wg-defstruct wg win
 
  (uid)
 
(wg-defstruct wg workgroup
 
  (uid (wg-generate-uid))
 
  (name)
 
  (modified)
 
  (parameters)
 
  (edges)
 
  (point)
 
  (start)
 
  (hscroll)
 
  (dedicated)
 
  (selected)
 
  (minibuffer-scroll)
 
  (buf-uid))
 
  (base-wconfig)
 
  (selected-frame-wconfig)
 
  (saved-wconfigs)
 
  (strong-buf-uids)
 
  (weak-buf-uids))
 

	
 
(wg-defstruct wg wtree
 
  (uid)
 
  (dir)
 
  (edges)
 
  (wlist))
 
(wg-defstruct wg workgroup-state
 
  (undo-pointer)
 
  (undo-list))
 

	
 
(wg-defstruct wg wconfig
 
  (uid (wg-generate-uid))
 
  (name)
 
  (parameters)
 
  (left)
 
@@ -60,33 +37,41 @@
 
  (width)
 
  (height)
 
  (vertical-scroll-bars)
 
  (scroll-bar-width)
 
  (wtree))
 

	
 
(wg-defstruct wg workgroup
 
  (uid (wg-generate-uid))
 
  (name)
 
  (modified)
 
(wg-defstruct wg wtree
 
  (uid)
 
  (dir)
 
  (edges)
 
  (wlist))
 

	
 
(wg-defstruct wg win
 
  (uid)
 
  (parameters)
 
  (base-wconfig)
 
  (selected-frame-wconfig)
 
  (saved-wconfigs)
 
  (strong-buf-uids)
 
  (weak-buf-uids))
 
  (edges)
 
  (point)
 
  (start)
 
  (hscroll)
 
  (dedicated)
 
  (selected)
 
  (minibuffer-scroll)
 
  (buf-uid))
 

	
 
(wg-defstruct wg session
 
(wg-defstruct wg buf
 
  (uid (wg-generate-uid))
 
  (name)
 
  (modified)
 
  (parameters)
 
  (file-name)
 
  (version wg-version)
 
  (workgroup-list)
 
  (buf-list))
 
  (point)
 
  (mark)
 
  (local-vars)
 
  (special-data)
 
  ;; This may be used later:
 
  (gc))
 

	
 
(wg-defstruct wg workgroup-state
 
  (undo-pointer)
 
  (undo-list))
 
(defmacro wg-workgroup-list ()
 
  "Setf'able `wg-current-session' modified slot accessor."
 
  `(wg-session-workgroup-list (wg-current-session)))
 

	
 
(provide 'workgroups-structs)
 
;;; workgroups-structs.el ends here
src/workgroups-support-macro.el
Show inline comments
 
deleted file
src/workgroups-utils-basic.el
Show inline comments
 
;;; workgroups-utils.el --- Utilities used by Workgroups
 
;;
 
;; Copyright (C) 2010, 2011 tlh
 
;;
 
;; Author: tlh <thunkout at gmail dot com>
 
;; Keywords: session management window-configuration persistence
 
;; Homepage: https://github.com/tlh/workgroups.el
 
;; 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 2 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, write to the Free
 
;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
;; MA 02111-1307 USA
 

	
 
;;; Commentary:
 
;;
 
;; A bunch of general purpose-ish utilities used by Workgroups.
 
;;
 
;;; Code:
 

	
 
;;; utils used in macros
 

	
 
(require 'cl-lib)
 
(require 'workgroups-faces)
 

	
 
(defmacro wg-with-gensyms (syms &rest body)
 
  "Bind all symbols in SYMS to `gensym's, and eval BODY."
 
  (declare (indent 1))
 
  `(let (,@(mapcar (lambda (sym) `(,sym (cl-gensym))) syms)) ,@body))
 

	
 
@@ -41,13 +19,13 @@
 
  "Bind the variables in ARGS to the result of EXPR and execute BODY.
 
Abbreviation of `destructuring-bind'."
 
  (declare (indent 2))
 
  `(cl-destructuring-bind ,args ,expr ,@body))
 

	
 
(defun wg-partition (list &optional n step)
 
  "Return list of N-length sublists of LIST, offset by STEP.
 
  "Take LIST, return a list of N length sublists, offset by STEP.
 
N defaults to 2, and STEP defaults to N.
 
Iterative to prevent stack overflow."
 
  (let* ((n (or n 2)) (step (or step n)) acc)
 
    (while list
 
      (push (wg-take list n) acc)
 
      (setq list (nthcdr step list)))
 
@@ -120,39 +98,21 @@ Else do ELSE...
 

	
 
(defmacro wg-awhen (test &rest body)
 
  "Anaphoric `when'."
 
  (declare (indent 1))
 
  `(wg-aif ,test (progn ,@body)))
 

	
 
(defmacro wg-acond (&rest clauses)
 
  "Anaphoric `cond'."
 
  (when clauses
 
    (wg-dbind ((condition . body) . rest) clauses
 
      `(wg-aif ,condition (progn ,@body)
 
         (wg-acond ,@rest)))))
 

	
 
(defmacro wg-aand (&rest args)
 
  "Anaphoric `and'."
 
  (cond ((null args) t)
 
        ((null (cdr args)) (car args))
 
        (t `(wg-aif ,(car args) (aand ,@(cdr args))))))
 

	
 
(defmacro wg-asetf (&rest places-and-values)
 
  "Anaphoric `setf'."
 
  `(progn ,@(mapcar (lambda (pv) `(let ((it ,(car pv))) (setf ,@pv)))
 
                    (wg-partition places-and-values 2))))
 

	
 

	
 

	
 
;;; other control structures
 

	
 
(defmacro wg-until (test &rest body)
 
  "`while' not."
 
  (declare (indent 1))
 
  `(while (not ,test) ,@body))
 

	
 
(defmacro wg-destructuring-dolist (spec &rest body)
 
  "Loop over a list.
 
Evaluate BODY, destructuring LIST into SPEC, then evaluate RESULT
 
to get a return value, defaulting to nil.  The only hitch is that
 
spec must end in dotted style, collecting the rest of the list
 
into a var, like so: (a (b c) . rest)
 
@@ -167,30 +127,12 @@ into a var, like so: (a (b c) . rest)
 
             (wg-dbind ,loopspec ,list-sym
 
               ,@body
 
               (setq ,list-sym ,rest)))
 
           ,result)))))
 

	
 

	
 

	
 
;;; boolean operators
 

	
 
(defmacro wg-eager-or (&rest conditions)
 
  "Evaluate all CONDITIONS.  Return the first non-nil return value."
 
  (let ((syms (mapcar (lambda (x) (cl-gensym)) conditions)))
 
    `(let ,(cl-mapcar 'list syms conditions)
 
       (or ,@syms))))
 

	
 
(defmacro wg-eager-and (&rest conditions)
 
  "Evaluate all conditions.  If any return nil, return nil.
 
Otherwise return the return value of the last condition."
 
  (let ((syms (mapcar (lambda (x) (cl-gensym)) conditions)))
 
    `(let ,(cl-mapcar 'list syms conditions)
 
       (and ,@syms))))
 

	
 

	
 

	
 
;;; numbers
 

	
 
(defun wg-step-to (n m step)
 
  "Increment or decrement N toward M by STEP.
 
Return M when the difference between N and M is less than STEP."
 
  (cond ((= n m) n)
 
@@ -383,38 +325,12 @@ If PARAM is not found, return DEFAULT which defaults to nil."
 
    (if found new (cons (cons key value) new))))
 

	
 
(defun wg-aremove (alist key)
 
  "`remove' KEY's key-value-pair from ALIST."
 
  (remove (assoc key alist) alist))
 

	
 
(defmacro wg-abind (alist binds &rest body)
 
  "Bind values in ALIST to symbols in BINDS, then eval BODY.
 
If an elt of BINDS is a symbol, use it as both the bound variable
 
and the key in ALIST.  If it is a cons, use the car as the bound
 
variable, and the cadr as the key."
 
  (declare (indent 2))
 
  (wg-with-gensyms (asym)
 
    `(let* ((,asym ,alist)
 
            ,@(wg-docar (bind binds)
 
                (let ((c (consp bind)))
 
                  `(,(if c (car bind) bind)
 
                    (wg-aget ,asym ',(if c (cadr bind) bind))))))
 
       ,@body)))
 

	
 

	
 

	
 
;;; hash-tables
 

	
 
(defun wg-fill-hash-table (table &rest key-value-pairs)
 
  "Fill TABLE with KEY-VALUE-PAIRS and return TABLE."
 
  (while key-value-pairs
 
    (puthash (car key-value-pairs) (cadr key-value-pairs) table)
 
    (setq key-value-pairs (cddr key-value-pairs)))
 
  table)
 

	
 

	
 

	
 
;;; symbols and strings
 

	
 
(defun wg-toggle (symbol)
 
  "Toggle SYMBOL's truthiness."
 
  (set symbol (not (symbol-value symbol))))
 
@@ -543,19 +459,12 @@ the cadr as the accessor function."
 
       ,@body)))
 

	
 

	
 

	
 
;;; misc
 

	
 
(defun wg-minibuffer-inactive-p ()
 
  "Return t when `minibuffer-depth' returns zero, nil otherwise."
 
  (zerop (minibuffer-depth)))
 

	
 
(defun wg-minibuffer-active-p ()
 
  "Return t when `minibuffer-depth' does not return zero, nil otherwise."
 
  (not (wg-minibuffer-inactive-p)))
 

	
 
(defun wg-fill-keymap (keymap &rest binds)
 
  "Return KEYMAP after defining in it all keybindings in BINDS."
 
  (while binds
 
    (define-key keymap (car binds) (cadr binds))
 
    (setq binds (cddr binds)))
 
@@ -565,74 +474,12 @@ the cadr as the accessor function."
 
  "Add FUNCTION to or remove it from HOOK, depending on REMOVE."
 
  (dolist (pair (wg-partition pairs 2))
 
    (funcall (if remove 'remove-hook 'add-hook)
 
             (car pair) (cadr pair))))
 

	
 

	
 
(defun wg-read-object (prompt test warning &optional initial-contents keymap
 
                              read hist default-value inherit-input-method)
 
  "PROMPT for an object that satisfies TEST, WARNING if necessary.
 
ARGS are `read-from-minibuffer's args, after PROMPT."
 
  (cl-labels ((read () (read-from-minibuffer
 
                      prompt initial-contents keymap read hist
 
                      default-value inherit-input-method)))
 
    (let ((obj (read)))
 
      (when (and (equal obj "") default-value) (setq obj default-value))
 
      (while (not (funcall test obj))
 
        (message warning)
 
        (sit-for wg-minibuffer-message-timeout)
 
        (setq obj (read)))
 
      obj)))
 

	
 
(defvar wg-readable-types
 
  '(integer float cons symbol vector string char-table bool-vector)
 
  "List of types with readable printed representations.")
 

	
 
(defun wg-is-readable-p (obj)
 
  "Return non-nil if OBJ's printed representation is readable."
 
  (memq (type-of obj) wg-readable-types))
 

	
 
(defun wg-take-until-unreadable (list)
 
  "Return a new list of elements of LIST up to the first unreadable element."
 
  (wg-take-until-fail 'wg-is-readable-p list))
 

	
 
(defun wg-add-face (facekey string)
 
  "Return a copy of STRING fontified according to FACEKEY.
 
FACEKEY must be a key in `wg-face-abbrevs'."
 
  (let ((face (wg-aget wg-face-abbrevs facekey))
 
        (string  (copy-sequence string)))
 
    (unless face (error "No face with key %s" facekey))
 
    (if (not wg-use-faces) string
 
      (put-text-property 0 (length string) 'face face string)
 
      string)))
 

	
 
(defmacro wg-fontify (&rest specs)
 
  "A small fontification DSL.
 
The results of all SPECS are `concat'd together.
 
If a spec is a cons with a keyword car, apply `wg-add-face' to it.
 
Other conses get evaluated, and should produce a strings.
 
If a spec is a string it is used unmodified.
 
Anything else is formatted with %s to produce a string."
 
  (declare (indent defun))
 
  `(concat
 
    ,@(wg-docar (spec specs)
 
        (cond ((and (consp spec)
 
                    (keywordp (car spec)))
 
               `(wg-add-face ,@spec))
 
              ;;((listp spec) (cdr (eval spec)))
 
              ;;((listp spec)
 
              ;; ;;(prin1-to-string (nth 1 (eval spec)))
 
              ;; )
 
              ((consp spec) spec)
 
              ((stringp spec) spec)
 
              (t `(format "%s" ,spec))))))
 

	
 
(defun wg-barf-on-active-minibuffer ()
 
  "Throw an error when the minibuffer is active."
 
  (when (wg-minibuffer-active-p)
 
    (error "Exit minibuffer to use workgroups functions!")))
 

	
 
(defmacro wg-set-parameter (place parameter value)
 
  "Set PARAMETER to VALUE at PLACE.
 
This needs to be a macro to allow specification of a setf'able place."
 
  (wg-with-gensyms (p v)
 
    `(let ((,p ,parameter) (,v ,value))
 
@@ -641,33 +488,83 @@ This needs to be a macro to allow specification of a setf'able place."
 
       (setf ,place (wg-aput ,place ,p ,v))
 
       ,v)))
 

	
 

	
 
;;; uid utils
 

	
 
(defun wg-time-to-b36 (&optional time)
 
(defun wg-time-to-b36 ()
 
  "Convert `current-time' into a b36 string."
 
  (apply 'concat (wg-docar (time (or time (current-time)))
 
  (apply 'concat (wg-docar (time (current-time))
 
                   (wg-int-to-b36 time 4))))
 

	
 
(defun wg-b36-to-time (b36)
 
  "Parse the time from UID."
 
  "Parse the time in B36 string from UID."
 
  (cl-loop for i from 0 to 8 by 4
 
           collect (wg-b36-to-int (cl-subseq b36 i (+ i 4)))))
 

	
 

	
 
(defalias 'wg-uid-to-time 'wg-b36-to-time)
 

	
 
(defun wg-generate-uid (&optional prefix)
 
  "Return a new uid, optionally prefixed by PREFIX."
 
  (concat prefix
 
          (wg-time-to-b36)
 
          "-"
 
          (wg-int-to-b36 string-chars-consed)))
 
  (concat prefix (wg-time-to-b36) "-" (wg-int-to-b36 string-chars-consed)))
 

	
 
(defun wg-uid-to-seconds (uid)
 
  "Return the `float-time' parsed from UID with `wg-uid-to-time'."
 
  (float-time (wg-uid-to-time uid)))
 

	
 

	
 
(defun wg-get-value (arg)
 
  "Get a value of ARG if it exists."
 
  (if (boundp `,arg) (eval arg)))
 

	
 
(defmacro wg-support (mode pkg params)
 
  "Macro to create (de)serialization functions for a buffer.
 
You need to save/restore a specific MODE which is loaded from a
 
package PKG.  In PARAMS you give local variables to save and a
 
deserialization function."
 
  `(let ((mode-str (symbol-name ,mode))
 
         (args ,params))
 

	
 
     (eval `(defun ,(intern (format "wg-deserialize-%s-buffer" mode-str)) (buffer)
 
              "DeSerialization function created with `wg-support'.
 
Gets saved variables and runs code to restore a BUFFER."
 
              (when (require ',,pkg nil 'noerror)
 
                (wg-dbind (this-function variables) (wg-buf-special-data buffer)
 
                  (let ((default-directory (car variables))
 
                        (df (cdr (assoc 'deserialize ',,params)))
 
                        (user-vars (car (cdr variables))))
 
                    (if df (funcall df buffer user-vars))
 
                    (current-buffer)
 
                    )))))
 

	
 
     (eval `(defun ,(intern (format "wg-serialize-%s-buffer" mode-str)) (buffer)
 
              "Serialization function created with `wg-support'.
 
Saves some variables to restore a BUFFER later."
 
              (when (get-buffer buffer)
 
                (with-current-buffer buffer
 
                  (when (eq major-mode ',,mode)
 
                    (let ((sf (cdr (assoc 'serialize ',,params)))
 
                          (save (cdr (assoc 'save ',,params))))
 
                      (list ',(intern (format "wg-deserialize-%s-buffer" mode-str))
 
                            (list default-directory
 
                                  (if sf (funcall sf buffer)
 
                                    (if save (mapcar 'wg-get-value save)))
 
                                  ))))))))
 
     ;; Maybe change a docstring for functions
 
     ;;(put (intern (format "wg-serialize-%s-buffer" (symbol-name mode)))
 
     ;;     'function-documentation
 
     ;;     (format "A function created by `wg-support'."))
 

	
 
     ;; Add function to `wg-special-buffer-serdes-functions' variable
 
     (eval `(add-to-list 'wg-special-buffer-serdes-functions
 
                         ',(intern (format "wg-serialize-%s-buffer" mode-str)) t))
 
     ))
 

	
 
(defvar wg-current-session nil "Current session object.")
 
(defun wg-current-session (&optional noerror)
 
  "Return `wg-current-session' or scream unless NOERROR."
 
  (or wg-current-session
 
      (unless noerror
 
        (error "No session is defined"))))
 

	
 

	
 
(provide 'workgroups-utils-basic)
 
;;; workgroups-utils-basic.el ends here
src/workgroups-variables.el
Show inline comments
 
;;; workgroups-variables --- Workgroups vars and consts
 
;;; Commentary:
 
;;; Code:
 

	
 
(defconst wg-version "1.1.0"
 
  "Current version of workgroups.")
 
(defconst wg-version "1.1.0" "Current version of Workgroups.")
 

	
 
;;; customization
 

	
 
(defgroup workgroups nil
 
  "Workgroups for Emacs -- Emacs session manager"
 
  :group 'convenience
 
  :version wg-version)
 
  :group 'convenience)
 

	
 
(defcustom workgroups-mode nil
 
  "Non-nil if Workgroups mode is enabled."
 
  :set 'custom-set-minor-mode
 
  :initialize 'custom-initialize-default
 
  :group 'workgroups
 
@@ -37,22 +35,12 @@
 
(defcustom wg-control-frames t
 
  "Save/restore frames."
 
  :group 'workgroups
 
  :type 'boolean)
 

	
 

	
 
;; keybinding customization
 

	
 
(defcustom wg-prefix-key (kbd "C-c z")
 
  "Workgroups' prefix key.
 
Setting this variable requires that `workgroups-mode' be turned
 
off and then on again to take effect."
 
  :type 'string
 
  :group 'workgroups)
 

	
 

	
 
;; hooks
 

	
 
(defcustom workgroups-mode-hook nil
 
  "Hook run when `workgroups-mode' is turned on."
 
  :type 'hook
 
  :group 'workgroups)
 
@@ -80,84 +68,26 @@ it should be made here."
 
  "Hook run before any function that triggers
 
`window-configuration-change-hook'."
 
  :type 'hook
 
  :group 'workgroups)
 

	
 

	
 
;; save and load customization
 
(defcustom wg-use-default-session-file (not (daemonp))
 
  "Generally, non-nil means take care of saving and loading automatically,
 
and nil means leave it up to the user.
 

	
 
FIXME: docstring this"
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-default-session-file
 
  "~/.emacs_workgroups"
 
  "Default filename to be used to save workgroups."
 
  :type 'file
 
  :group 'workgroups)
 

	
 
(defcustom wg-open-this-wg nil
 
  "Try to open this workgroup on start. If nil - nothing happens."
 
  "Try to open this workgroup on start.
 
If nil - nothing happens."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-switch-to-first-workgroup-on-find-session-file t
 
  "Non-nil means switch to the first workgroup in a session file
 
when it's found with `wg-find-session-file'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-emacs-exit-save-behavior 'save
 
  "Determines save behavior on Emacs exit.
 
Possible values:
 

	
 
`ask'           Ask the user whether to save if there are unsaved changes
 

	
 
`save'          Call `wg-save-session' when there are unsaved changes
 

	
 
Anything else   Exit Emacs without saving changes"
 
  :type 'symbol
 
  :group 'workgroups)
 

	
 
(defcustom wg-workgroups-mode-exit-save-behavior 'save
 
  "Determines save behavior on `workgroups-mode' exit.
 
Possible values:
 

	
 
`ask'           Ask the user whether to saveif there are unsaved changes
 

	
 
`save'          Call `wg-save-session' when there are unsaved changes
 

	
 
Anything else   Exit `workgroups-mode' without saving changes"
 
  :type 'symbol
 
  :group 'workgroups)
 

	
 

	
 
;; minibuffer customization
 

	
 
(defcustom wg-confirm-on-get-workgroup-create nil
 
  "Non-nil means request confirmation before creating a new
 
workgroup when `wg-get-workgroup-create' is called with a string
 
that doesn't name an existing workgroup."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-no-confirm-on-destructive-operation nil
 
  "Non-nil means don't request confirmation before various
 
destructive operations, like `wg-reset'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-minibuffer-message-timeout 0.75
 
  "Bound to `minibuffer-message-timeout' when messaging while the
 
minibuffer is active."
 
  :type 'float
 
  :group 'workgroups)
 

	
 

	
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;;
 
;; FIXME:
 
;;
 
;; Only set `wg-workgroup-base-wconfig' on `wg-write-session-file' or
 
@@ -213,49 +143,12 @@ necessary to properly restore the original value of the variable.
 
For example, in the case of `major-mode' it should funcall the
 
value (a major-mode function symbol) rather than just assigning
 
it to `major-mode'."
 
  :type 'alist
 
  :group 'workgroups)
 

	
 
(defcustom wg-special-buffer-serdes-functions
 
  '(wg-serialize-comint-buffer
 
    wg-serialize-speedbar-buffer)
 
  "List of functions providing special buffer serialization/deserialization.
 

	
 
Use `wg-support' macro and this variable will be filled
 
automatically.
 

	
 
An entry should be either a function symbol or a lambda, and should
 
accept a single Emacs buffer object as an argument.
 

	
 
When a buffer is to be serialized, it is passed to each of these
 
functions in turn until one returns non-nil, or the list ends.  A
 
return value of nil indicates that the function can't handle
 
buffers of that type.  A non-nil return value indicates that it
 
can.  The first non-nil return value becomes the buffer's special
 
serialization data.  The return value should be a cons, with a
 
deserialization function (a function symbol or a lambda) as the car,
 
and any other serialization data as the cdr.
 

	
 
When it comes time to deserialize the buffer, the deserialization
 
function (the car of the cons mentioned above) is passed the
 
wg-buf object, from which it should restore the buffer.  The
 
special serialization data itself can be accessed
 
with (cdr (wg-buf-special-data <wg-buf>)).  The deserialization
 
function must return the restored Emacs buffer object.
 

	
 
See the definitions of the functions in this list for examples of
 
how to write your own."
 
  :type 'alist
 
  :group 'workgroups)
 

	
 
(defcustom wg-default-buffer "*scratch*"
 
  "Buffer made visible a window when the window's actual buffer
 
can't be restored.  Also used when a blank workgroup is created."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-nowg-string "No workgroups"
 
  "Display this string if there are no workgroups and
 
`wg-display-nowg' is t."
 
  :type 'string
 
  :group 'workgroups)
 
@@ -269,19 +162,12 @@ can't be restored.  Also used when a blank workgroup is created."
 

	
 
(defcustom wg-restore-remote-buffers t
 
  "Restore buffers that get \"t\" with `file-remote-p'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-restore-associated-buffers nil
 
  "Non-nil means restore ALL buffers associated (opened in) with
 
the workgroup on workgroup restore.  \"nil\" means to restore
 
only needed buffers to show them to you."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-restore-frame-position t
 
  "Non-nil means restore frame position on workgroup restore."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-restore-scroll-bars t
 
@@ -330,22 +216,17 @@ say, irc buffers where `point-max' is constantly increasing."
 

	
 
When nil - save/restore frame parameters to/from the first workgroup."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 

	
 
;; wconfig undo/redo customization
 

	
 
(defcustom wg-wconfig-undo-list-max 20
 
  "Number of past window configs to retain for undo."
 
  :type 'integer
 
  :group 'workgroups)
 

	
 

	
 
;; wconfig kill-ring customization
 

	
 
(defcustom wg-wconfig-kill-ring-max 20
 
  "Maximum length of the `wg-wconfig-kill-ring'."
 
  :type 'integer
 
  :group 'workgroups)
 

	
 

	
 
@@ -357,14 +238,12 @@ Nil means ido and iswitchb behave normally.  See
 
`wg-buffer-list-filter-definitions' for more info."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-buffer-list-filter-definitions
 
  '((all "all" wg-buffer-list-filter-all)
 
    (associated "associated" wg-buffer-list-filter-associated)
 
    (unassociated "unassociated" wg-buffer-list-filter-unassociated)
 
    (fallback "fallback" nil))
 
  "List of buffer list filter definitions.
 
Each entry should be a list containing an identifier symbol, a
 
prompt string, and a function form that's funcall'd to produce
 
the filtered buffer-list.
 

	
 
@@ -377,50 +256,26 @@ buffers.  The function should return a new list of live buffers,
 
typically by filtering its second argument in some way.
 

	
 
Default buffer-list-filters include:
 

	
 
`all'           All buffer names
 

	
 
`associated'    Only the names of those live buffers that have
 
                been associated with the current workgroup
 

	
 
`unassociated'  Only the names of those live buffers that are
 
                unassociated with the current workgroup
 

	
 
`fallback'      A special case used to fallback to the
 
                original (non-ido/iswitchb) Emacs command.
 
                `fallback' isn't actually a buffer-list-filter
 
                itself, but can be used in
 
                `wg-buffer-list-filter-order-alist' just the
 
                same.
 

	
 
A few example custom buffer-list filtration functions are
 
included, like `wg-buffer-list-filter-home-dir',
 
`wg-buffer-list-filter-irc' and `wg-buffer-list-filter-elisp'.
 
See their definitions for more info on how they're defined, and
 
the utilities they're built on.
 

	
 
Here's an example of how to add an `elisp' buffer-list-filter
 
definition to `wg-buffer-list-filter-definitions' using the
 
example function `wg-buffer-list-filter-elisp':
 

	
 
(add-to-list
 
 'wg-buffer-list-filter-definitions
 
 '(elisp \"elisp\" wg-buffer-list-filter-elisp))
 

	
 
After this form has been evaluated, `elisp' can be used wherever
 
other buffer-list-filter identifiers are used, like in
 
`wg-buffer-list-filter-order-alist'.
 

	
 
Becomes workgroup-local when set with `wg-set-workgroup-parameter'.
 
Becomes session-local when set with `wg-set-session-parameter'."
 
  :type 'list
 
  :group 'workgroups)
 

	
 
(defcustom wg-buffer-list-filter-order-alist
 
  '((default associated unassociated all fallback))
 
  '((default all fallback))
 
  "Alist defining the order in which filtered buffer-lists are presented.
 

	
 
The car of each entry should be the symbol of the original Emacs
 
command (not the ido or iswitchb remappings) -- i.e. one of
 
`switch-to-buffer', `switch-to-buffer-other-window',
 
`switch-to-buffer-other-frame', `kill-buffer', `next-buffer',
 
@@ -445,295 +300,32 @@ current buffer is in the center of the list.  This can make it
 
easier to see the where `wg-previous-buffer' will take you, but
 
it doesn't look right if the buffer list display is long enough
 
to wrap in the miniwindow."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-buffer-auto-association-on t
 
  "Non-nil means buffer auto-association is on.
 
nil means it's off.  See `wg-buffer-auto-association'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-buffer-auto-association 'weak
 
  "Specifies the behavior for auto-associating buffers with workgroups.
 

	
 
When a buffer is made visible in a window it can be automatically
 
associated with the current workgroup in the window's frame.
 
This setting determines whether and how that happens.
 

	
 
Allowable values:
 

	
 
`weak' - weakly associate the buffer with the workgroup
 

	
 
`strong' - strongly associate the buffer with the workgroup
 

	
 
A function (a function-symbol or a lambda) - `funcall' the function to
 
determine whether and how to associate the buffer with the
 
workgroup.  The function should accept two arguments -- the
 
buffer and the workgroup -- and should return one of the
 
allowable values for this variable.
 

	
 
`nil' or any other value - don't associate the buffer with the
 
workgroup.
 

	
 
Becomes workgroup-local when set with `wg-set-workgroup-parameter'.
 
Becomes session-local when set with `wg-set-session-parameter'."
 
  :type 'sexp
 
  :group 'workgroups)
 

	
 
(defcustom wg-dissociate-buffer-on-kill-buffer t
 
  "Non-nil means dissociate from the current workgroup buffers
 
killed with `kill-buffer'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-switch-to-buffer nil
 
  "Non-nil means remap `switch-to-buffer' to `wg-switch-to-buffer'."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-switch-to-buffer-other-window nil
 
  "Non-nil means remap `switch-to-buffer-other-window' to
 
`wg-switch-to-buffer-other-window'.  Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-switch-to-buffer-other-frame nil
 
  "Non-nil means remap `switch-to-buffer-other-frame' to
 
`wg-switch-to-buffer-other-frame'.  Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-kill-buffer nil
 
  "Non-nil means remap `kill-buffer' to `wg-kill-buffer'.
 
Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-display-buffer nil
 
  "Non-nil means remap `display-buffer' to `wg-display-buffer'.
 
Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-insert-buffer nil
 
  "Non-nil means remap `insert-buffer' to `wg-insert-buffer'.
 
Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-next-buffer nil
 
  "Non-nil means remap `next-buffer' to `wg-next-buffer'.
 
Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-previous-buffer nil
 
  "Non-nil means remap `previous-buffer' to `wg-previous-buffer'.
 
Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-remap-bury-buffer 'bury
 
(defcustom wg-remap-bury-buffer nil
 
  "Non-nil means remap `bury-buffer'.
 
`banish' means remap `bury-buffer' to `wg-banish-buffer'.
 
`bury' or other non-nil means remap `bury-buffer' to
 
`wg-bury-buffer'.  Otherwise, don't remap."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-ido-entry-buffer-replacement-regexp "^ .*Minibuf.*$"
 
  "Regexp matching the name of a buffer to replace `ido-entry-buffer'.
 
The regexp should match the name of a live buffer that will never
 
be a completion candidate under normal circumstances.  You
 
probably don't want to change this.  See
 
`wg-get-sneaky-ido-entry-buffer-replacement'."
 
  :type 'regexp
 
  :group 'workgroups)
 

	
 

	
 
;; mode-line customization
 

	
 
(defcustom wg-mode-line-display-on t
 
  "Toggles Workgroups' mode-line display."
 
  :type 'boolean
 
  :group 'workgroups
 
  :set (lambda (sym val)
 
         (custom-set-default sym val)
 
         (force-mode-line-update)))
 

	
 
(defcustom wg-mode-line-use-faces nil
 
  "Non-nil means use faces in the mode-line display.
 
It can be tricky to choose faces that are visible in both active
 
and inactive mode-lines, so this feature defaults to off."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-disable (featurep 'powerline)
 
  "Do not do any modeline modifications."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-only-name t
 
  "Display only workgroup name in modeline without any flags."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-left-brace "("
 
  "String displayed at the left of the mode-line display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-right-brace ")"
 
  "String displayed at the right of the mode-line display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-divider ":"
 
  "String displayed between elements of the mode-line display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-strongly-associated
 
  #("@" 0 1 (help-echo "This buffer is strongly associated with the \
 
current workgroup"))
 
  "Indicates that a buffer is strongly associated with the current workgroup."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-weakly-associated
 
  #("~" 0 1 (help-echo "This buffer is weakly associated with the \
 
current workgroup"))
 
  "Indicates that a buffer is weakly associated with the current workgroup."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-unassociated
 
  #("-" 0 1 (help-echo "This buffer is unassociated with the \
 
current workgroup"))
 
  "Indicates that a buffer is unassociated with the current workgroup."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-window-dedicated
 
  #("#" 0 1 (help-echo "This window is dedicated to its buffer."))
 
  "Indicates that the window is dedicated to its buffer."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-window-undedicated
 
  #("-" 0 1 (help-echo "This window is not dedicated to its buffer."))
 
  "Indicates that the window is not dedicated to its buffer."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-session-modified
 
  #("*" 0 1 (help-echo "The session is modified"))
 
  "Indicates that the session is modified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-session-unmodified
 
  #("-" 0 1 (help-echo "The session is unmodified"))
 
  "Indicates that the session is unmodified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-workgroup-modified
 
  #("*" 0 1 (help-echo "The current workgroup is modified"))
 
  "Indicates that the current workgroup is modified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-mode-line-decor-workgroup-unmodified
 
  #("-" 0 1 (help-echo "The current workgroup is unmodified"))
 
  "Indicates that the current workgroup is unmodified."
 
  :type 'string
 
  :group 'workgroups)
 

	
 

	
 
;; display customization
 

	
 
(defcustom wg-use-faces t
 
  "Non-nil means use faces in various displays."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-time-format "%H:%M:%S %A, %B %d %Y"
 
  "Format string for time display.  Passed to `format-time-string'."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-display-battery t
 
  "Non-nil means include `battery', when available, in the time display."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-left-brace "( "
 
  "String displayed to the left of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-right-brace " )"
 
  "String displayed to the right of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-divider " | "
 
  "String displayed between elements of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-current-left "-<{ "
 
  "String displayed to the left of the current element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-current-right " }>-"
 
  "String displayed to the right of the current element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-previous-left "< "
 
  "String displayed to the left of the previous element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-list-display-decor-previous-right " >"
 
  "String displayed to the right of the previous element of the list display."
 
  :type 'string
 
  :group 'workgroups)
 

	
 
(defcustom wg-associate-buffers t
 
  "Non-nil means when emacs chooses a buffer to display in a
 
workgroup, prefer buffers whose most recent appearance was in
 
that workgroup."
 
  :type 'boolean
 
  :group 'workgroups)
 

	
 
;;; vars
 

	
 
(defvar workgroups-mode-map nil
 
  "Workgroups Mode's keymap")
 

	
 
(defvar wg-current-session nil
 
  "Current session object.")
 

	
 
(defvar wg-workgroups-mode-minor-mode-map-entry nil
 
  "Workgroups' minor-mode-map entry.")
 

	
 
(defvar wg-wconfig-kill-ring nil
 
  "Ring of killed or kill-ring-saved wconfigs.")
 

	
 
(defvar wg-last-message nil
 
  "Holds the last message Workgroups sent to the echo area.")
 

	
 
(defvar wg-face-abbrevs nil
 
  "Assoc list mapping face abbreviations to face names.")
 

	
 
(defvar wg-buffer-uid nil
 
  "Symbol for the current buffer's wg-buf's uid.
 
Every Workgroups buffer object (wg-buf) has a uid.  When
 
Workgroups creates or encounters an Emacs buffer object
 
corresponding to a wg-buf, it tags it with the wg-buf's uid to
 
unambiguously pair the two.")
 
@@ -756,21 +348,13 @@ temporarily disable flagging `modified'.")
 
  "Flag set by `wg-update-working-wconfig-hook'.")
 

	
 
(defvar wg-undoify-window-configuration-change t
 
  "Flag unset when changes to the window config shouldn't cause
 
workgroups' undo info to be updated.")
 

	
 
(defvar wg-just-exited-minibuffer nil
 
  "Flag set by `minibuffer-exit-hook' to exempt from
 
undoification those window-configuration changes caused by
 
exiting the minibuffer.  This is ugly, but necessary.  It may
 
seem like we could just null out
 
`wg-undoify-window-configuration-change' in
 
`minibuffer-exit-hook', but that also prevents undoification of
 
window configuration changes triggered by commands called with
 
`execute-extended-command' -- i.e. it's just too coarse.")
 

	
 

	
 

	
 
;; buffer-list-filter vars
 

	
 
(defvar wg-current-workgroup nil
 
  "Bound to the current workgroup in `wg-with-buffer-list-filters'.")
 
@@ -791,21 +375,12 @@ the buffer-list-filter is cycled.")
 
    (switch-to-buffer-other-frame  . other-frame)
 
    (kill-buffer                   . kill)
 
    (insert-buffer                 . insert)
 
    (display-buffer                . display))
 
  "Alist mapping buffer commands to ido buffer methods.")
 

	
 
(defvar wg-iswitchb-method-translations
 
  `((switch-to-buffer              . samewindow)
 
    (switch-to-buffer-other-window . otherwindow)
 
    (switch-to-buffer-other-frame  . otherframe)
 
    (kill-buffer                   . kill)
 
    (insert-buffer                 . insert)
 
    (display-buffer                . display))
 
  "Alist mapping buffer commands to iswitchb buffer methods.")
 

	
 
(defvar wg-buffer-internal-default-buffer nil
 
  "Bound to `wg-buffer-internal's optional DEFAULT argument for
 
use by buffer list filtration hooks.")
 

	
 
(defvar wg-temp-buffer-list nil
 
  "Dynamically bound to the filtered buffer list in
 
@@ -843,79 +418,10 @@ use by buffer list filtration hooks.")
 
  "Non-nil means update `selected-frame's current workgroup's
 
working wconfig before `select-frame' selects a new frame.
 
let-bind this to nil around forms in which you don't want this to
 
happen.")
 

	
 

	
 
(defvar wg-buffer-workgroup nil
 
  "Buffer-local variable associating each buffer with the
 
  workgroup in which it most recently appeared.")
 
(make-variable-buffer-local 'wg-buffer-workgroup)
 

	
 
(defvar wg-deactivation-list nil
 
  "A stack of workgroups that are currently being switched away from.
 
Used to avoid associating the old workgroup's buffers with the
 
new workgroup during a switch.")
 

	
 
(defvar wg-incorrectly-restored-bufs nil
 
  "FIXME: docstring this.")
 
;; TODO: check it on switching WG
 

	
 
(defvar wg-record-incorrectly-restored-bufs nil
 
  "FIXME: docstring this.")
 

	
 
;;; faces
 

	
 
(defmacro wg-defface (face key spec doc &rest args)
 
  "`defface' wrapper adding a lookup key used by `wg-fontify'."
 
  (declare (indent 2))
 
  `(progn
 
     (cl-pushnew (cons ,key ',face) wg-face-abbrevs :test #'equal)
 
     (defface ,face ,spec ,doc ,@args)))
 

	
 
(wg-defface wg-current-workgroup-face :cur
 
  '((t :inherit font-lock-constant-face :bold nil))
 
  "Face used for current elements in list displays."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-previous-workgroup-face :prev
 
  '((t :inherit font-lock-keyword-face :bold nil))
 
  "Face used for the name of the previous workgroup in the list display."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-other-workgroup-face :other
 
  '((t :inherit font-lock-string-face :bold nil))
 
  "Face used for the names of other workgroups in the list display."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-command-face :cmd
 
  '((t :inherit font-lock-function-name-face :bold nil))
 
  "Face used for command/operation strings."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-divider-face :div
 
  '((t :inherit font-lock-builtin-face :bold nil))
 
  "Face used for dividers."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-brace-face :brace
 
  '((t :inherit font-lock-builtin-face :bold nil))
 
  "Face used for left and right braces."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-message-face :msg
 
  '((t :inherit font-lock-string-face :bold nil))
 
  "Face used for messages."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-mode-line-face :mode
 
  '((t :inherit font-lock-doc-face :bold nil))
 
  "Face used for workgroup position and name in the mode-line display."
 
  :group 'workgroups)
 

	
 
(wg-defface wg-filename-face :file
 
  '((t :inherit font-lock-keyword-face :bold nil))
 
  "Face used for filenames."
 
  :group 'workgroups)
 

	
 
(provide 'workgroups-variables)
 
;;; workgroups-variables.el ends here

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)