Changeset - 295f3038db4d
[Not reviewed]
0 11 0
Sergey Pashinin - 12 years ago 2014-02-19 14:12:22
sergey@pashinin.com
Using cl-lib and it's functions
11 files changed with 127 insertions and 121 deletions:
0 comments (0 inline, 0 general)
src/workgroups-advice.el
Show inline comments
 
@@ -39,7 +39,7 @@ Frame defaults to `selected-frame'.  See `wg-buffer-auto-association'."
 

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

	
 
(macrolet ((define-p-w-c-c-h-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
src/workgroups-commands-minibuffer.el
Show inline comments
 
@@ -34,7 +34,7 @@ in which case call `wg-previous-buffer-list-filter'."
 
  (wg-when-let
 
      ((mode (wg-read-buffer-mode))
 
       (buffer (wg-current-match mode))
 
       (pos (wg-position buffer (wg-filtered-buffer-list t) :test 'equal)))
 
       (pos (cl-position buffer (wg-filtered-buffer-list t) :test 'equal)))
 
    (wg-workgroup-dissociate-bufobj (wg-current-workgroup) buffer)
 
    (wg-set-current-matches
 
     (wg-rotate-list (wg-filtered-buffer-list t) pos) mode)))
 
@@ -45,7 +45,7 @@ in which case call `wg-previous-buffer-list-filter'."
 
  (wg-when-let
 
      ((mode (wg-read-buffer-mode))
 
       (buffer (wg-current-match mode))
 
       (pos (wg-position buffer (wg-filtered-buffer-list t) :test 'equal)))
 
       (pos (cl-position buffer (wg-filtered-buffer-list t) :test 'equal)))
 
    (wg-workgroup-associate-bufobj (wg-current-workgroup) buffer)
 
    (wg-set-current-matches
 
     (wg-rotate-list (wg-filtered-buffer-list t) pos) mode)))
 
@@ -56,8 +56,8 @@ in which case call `wg-previous-buffer-list-filter'."
 
  (wg-workgroup-dissociate-weakly-associated-buffers (wg-current-workgroup))
 
  (wg-set-current-matches
 
   (let ((remaining (wg-filtered-buffer-list t)))
 
     (wg-remove-if-not (lambda (match) (member match remaining))
 
                    (wg-current-matches)))))
 
     (cl-remove-if-not (lambda (match) (member match remaining))
 
                       (wg-current-matches)))))
 

	
 
(provide 'workgroups-commands-minibuffer)
 
;;; workgroups-commands-minibuffer.el ends here
src/workgroups-commands.el
Show inline comments
 
@@ -2,6 +2,11 @@
 
;;; Commentary:
 
;;; Code:
 

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

	
 
(require 'ring)
 
(require 'workgroups-variables)
 
(require 'workgroups-utils-basic)
 
@@ -44,7 +49,7 @@ Use `current-prefix-arg' for N if non-nil.  Otherwise N defaults to 1."
 
    (wg-switch-to-workgroup
 
     (or (nth index wl) (error "There are only %d workgroups" (length wl))))))
 

	
 
(macrolet
 
(cl-macrolet
 
    ((define-range-of-switch-to-workgroup-at-index (num)
 
       `(progn
 
          ,@(wg-docar (i (wg-range 0 num))
 
@@ -509,7 +514,7 @@ See `wg-workgroup-cycle-bufobj-association-type' for details."
 
    (force-mode-line-update)
 
    (wg-fontified-message
 
      (:cur (buffer-name buffer))
 
      (:cmd (case type
 
      (:cmd (cl-case type
 
              (strong " strongly associated with ")
 
              (weak " weakly associated with ")
 
              (otherwise " unassociated with ")))
 
@@ -673,7 +678,7 @@ the session regardless of whether it's been modified."
 

	
 
(defun wg-save-session-on-exit (behavior)
 
  "Perform session-saving operations based on BEHAVIOR."
 
  (case behavior
 
  (cl-case behavior
 
    (ask (wg-query-and-save-if-modified))
 
    (save
 
     (if (wg-determine-session-save-file-name)
src/workgroups-functions.el
Show inline comments
 
@@ -2,7 +2,6 @@
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'dflet)
 
(require 'workgroups-compat)
 
(require 'workgroups-variables)
 
(require 'workgroups-utils-basic)
 
@@ -33,7 +32,7 @@
 
(defun wg-modified-p ()
 
  "Return t when the current session or any of its workgroups are modified."
 
  (or (wg-session-modified (wg-current-session))
 
      (wg-some 'wg-workgroup-modified (wg-workgroup-list))))
 
      (cl-some 'wg-workgroup-modified (wg-workgroup-list))))
 

	
 
(defun wg-mark-everything-unmodified ()
 
  "Mark the session and all workgroups as unmodified."
 
@@ -76,7 +75,7 @@ Return value."
 
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 (wg-gensym))
 
  (let* ((undefined (cl-gensym))
 
         (value (wg-session-parameter session variable undefined)))
 
    (if (not (eq value undefined)) value
 
      (symbol-value variable))))
 
@@ -91,21 +90,21 @@ resolved by Emacs."
 

	
 
(defun wg-bufobj-uid (bufobj)
 
  "Return BUFOBJ's uid."
 
  (etypecase bufobj
 
  (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."
 
  (etypecase bufobj
 
  (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."
 
  (etypecase bufobj
 
  (cl-etypecase bufobj
 
    (buffer (buffer-file-name bufobj))
 
    (wg-buf (wg-buf-file-name bufobj))
 
    (string (wg-bufobj-file-name (wg-get-buffer bufobj)))))
 
@@ -117,7 +116,7 @@ It's stored in BUF's local-vars list, since it's a local variable."
 

	
 
(defun wg-bufobj-major-mode (bufobj)
 
  "Return BUFOBJ's major-mode."
 
  (etypecase bufobj
 
  (cl-etypecase bufobj
 
    (buffer (wg-buffer-major-mode bufobj))
 
    (wg-buf (wg-buf-major-mode bufobj))
 
    (string (wg-buffer-major-mode bufobj))))
 
@@ -133,20 +132,20 @@ It's stored in BUF's local-vars list, since it's a local variable."
 

	
 
(defun wg-find-bufobj (bufobj bufobj-list)
 
  "Find BUFOBJ in BUFOBJ-LIST, testing with `wg-equal-bufobjs'."
 
  (wg-find bufobj bufobj-list :test '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."
 
  (wg-find uid bufobj-list :test 'string= :key 'wg-bufobj-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."
 
  (wg-find buf buf-list))
 
  (cl-find buf buf-list))
 

	
 
(defun wg-find-buffer-in-buffer-list (buffer-or-name buffer-list)
 
  "Find BUFFER-OR-NAME in BUFFER-LIST."
 
  (wg-find (wg-get-buffer buffer-or-name) buffer-list :key 'wg-get-buffer))
 
  (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."
 
@@ -179,7 +178,7 @@ and it's not equal to UID, error."
 

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

	
 
(defun wg-window-point (ewin)
 
  "Return `point' or :max.  See `wg-restore-point-max'.
 
@@ -228,7 +227,7 @@ in either case."
 
(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'."
 
  (etypecase bufobj
 
  (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)))))
 
@@ -332,19 +331,19 @@ BUFFER or `wg-default-buffer' is visible in the only window."
 

	
 
(defun wg-w-edges (w)
 
  "Return W's edge list."
 
  (etypecase w
 
  (cl-etypecase w
 
    (wg-win (wg-win-edges w))
 
    (wg-wtree (wg-wtree-edges w))))
 

	
 
(defun wg-copy-w (w)
 
  "Return a copy of W.  W should be a wg-win or a wg-wtree."
 
  (etypecase w
 
  (cl-etypecase w
 
    (wg-win (wg-copy-win w))
 
    (wg-wtree (wg-copy-wtree w))))
 

	
 
(defun wg-set-edges (w edges)
 
  "Set W's edge list, and return W."
 
  (etypecase w
 
  (cl-etypecase w
 
    (wg-win (setf (wg-win-edges w) edges))
 
    (wg-wtree (setf (wg-wtree-edges w) edges)))
 
  w)
 
@@ -390,7 +389,7 @@ BUFFER or `wg-default-buffer' is visible in the only window."
 

	
 
(defun wg-w-edge-operation (w edges op)
 
  "Return a copy of W with its edges mapped against EDGES through OP."
 
  (wg-set-edges w (wg-mapcar* op (wg-w-edges w) edges)))
 
  (wg-set-edges w (cl-mapcar op (wg-w-edges w) edges)))
 

	
 
(defun wg-first-win (w)
 
  "Return the first actual window in W."
 
@@ -444,7 +443,7 @@ BUFFER or `wg-default-buffer' is visible in the only window."
 
        ((and (wg-wtree-p w1) (wg-wtree-p w2))
 
         (and (eq (wg-wtree-dir w1) (wg-wtree-dir w2))
 
              (equal (wg-wtree-edges w1) (wg-wtree-edges w2))
 
              (wg-every #'wg-equal-wtrees
 
              (cl-every #'wg-equal-wtrees
 
                     (wg-wtree-wlist w1)
 
                     (wg-wtree-wlist w2))))))
 

	
 
@@ -538,7 +537,7 @@ Otherwise, reverse WTREE vertically."
 
                      (wg-make-wtree
 
                       :dir (wg-wtree-dir w)
 
                       :edges (wg-wtree-edges w)
 
                       :wlist (wg-aif (wg-find t wlist :key 'wg-win-selected)
 
                       :wlist (wg-aif (cl-find t wlist :key 'wg-win-selected)
 
                                  (wg-cyclic-offset-elt it wlist offset)
 
                                (mapcar #'inner wlist)))))))
 
    (wg-normalize-wtree (inner wtree))))
 
@@ -559,7 +558,7 @@ KEY non returns returns a list of WTREE's wins.
 
KEY non-nil returns a list of the results of calling KEY on each win."
 
  (dflet
 
      ((inner (w) (if (wg-win-p w) (list (if key (funcall key w) w))
 
                    (wg-mapcan 'inner (wg-wtree-wlist w)))))
 
                    (cl-mapcan 'inner (wg-wtree-wlist w)))))
 
    (inner wtree)))
 

	
 
(defun wg-win-list (wtree)
 
@@ -582,10 +581,10 @@ KEY non-nil returns a list of the results of calling KEY on each win."
 

	
 
(defun wg-find-workgroup-by (slotkey value &optional noerror)
 
  "Return the workgroup on which ACCESSOR returns VALUE or error."
 
  (let ((accessor (ecase slotkey
 
  (let ((accessor (cl-ecase slotkey
 
                    (:name 'wg-workgroup-name)
 
                    (:uid  'wg-workgroup-uid))))
 
    (or (wg-find value (wg-workgroup-list-or-error noerror) :test 'equal :key accessor)
 
    (or (cl-find value (wg-workgroup-list-or-error noerror) :test 'equal :key accessor)
 
        (unless noerror
 
          (error "No are no workgroups with a %S of %S"
 
                 accessor value)))))
 
@@ -682,7 +681,7 @@ current workgroup, or if VARIABLE does not have a workgroup-local
 
binding in WORKGROUP, resolve VARIABLE with `wg-session-local-value'."
 
  (let ((workgroup (wg-get-workgroup workgroup t)))
 
    (if (not workgroup) (wg-session-local-value variable)
 
      (let* ((undefined (wg-gensym))
 
      (let* ((undefined (cl-gensym))
 
             (value (wg-workgroup-parameter workgroup variable undefined)))
 
        (if (not (eq value undefined)) value
 
          (wg-session-local-value variable))))))
 
@@ -705,7 +704,7 @@ binding in WORKGROUP, resolve VARIABLE with `wg-session-local-value'."
 
(defun wg-workgroup-associated-buffers (workgroup &optional initial names)
 
  "Return a list of WORKGROUP's live associated buffers."
 
  (let ((assoc-bufs (wg-workgroup-associated-bufs workgroup)))
 
    (wg-remove-if-not
 
    (cl-remove-if-not
 
     (lambda (buffer) (wg-find-buffer-in-buf-list buffer assoc-bufs))
 
     (or initial (buffer-list)))))
 

	
 
@@ -759,7 +758,7 @@ WEAK non-nil means weakly associate it.  Otherwise strongly associate it."
 
If it's strongly associated with the workgroup, weakly associate it.
 
If it's weakly associated with the workgroup, dissociate it.
 
If it's unassociated with the workgroup, mark it as strongly associated."
 
  (case (wg-workgroup-bufobj-association-type workgroup bufobj)
 
  (cl-case (wg-workgroup-bufobj-association-type workgroup bufobj)
 
    (strong (wg-workgroup-weakly-associate-bufobj workgroup bufobj) 'weak)
 
    (weak (wg-workgroup-dissociate-bufobj workgroup bufobj) nil)
 
    (otherwise (wg-workgroup-strongly-associate-bufobj workgroup bufobj) 'strong)))
 
@@ -799,7 +798,7 @@ If it's unassociated with the workgroup, mark it as strongly associated."
 
  "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 (case key (symbol 0) (indicator 1) (constructor 2))))
 
  (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))
 
@@ -844,24 +843,24 @@ INITIAL non-nil should be an initial buffer-list to filter.  It defaults to
 
(defun wg-buffer-list-filter-unassociated (workgroup initial)
 
  "Return only those buffer unassociated with WORKGROUP."
 
  (let ((buffers (wg-workgroup-associated-buffers workgroup initial)))
 
    (wg-remove-if (lambda (buffer) (member buffer buffers)) initial)))
 
    (cl-remove-if (lambda (buffer) (member buffer buffers)) initial)))
 

	
 

	
 
;; buffer-list filtration utils
 

	
 
(defun wg-filter-buffer-list-by-regexp (regexp buffer-list)
 
  "Return only those buffers in BUFFER-LIST with names matching REGEXP."
 
  (wg-remove-if-not (lambda (bname) (string-match regexp bname))
 
  (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."
 
  (wg-remove-if-not (lambda (f) (when f (wg-file-under-root-path-p root-dir f)))
 
  (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."
 
  (wg-remove-if-not (lambda (mm) (eq mm major-mode))
 
  (cl-remove-if-not (lambda (mm) (eq mm major-mode))
 
                 buffer-list :key 'wg-buffer-major-mode))
 

	
 

	
 
@@ -912,7 +911,7 @@ Binds `wg-current-buffer-list-filter-id' in BODY."
 
         (while 'your-mom
 
           (let* ((wg-current-buffer-list-filter-id (car ,order))
 
                  (,status (catch 'wg-action (list 'done (progn ,@body)))))
 
             (case (car ,status)
 
             (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)))
 
@@ -1082,9 +1081,9 @@ that name, return nil.  If WCONFIG-OR-NAME is a wconfig, and it
 
is a member of WORKGROUP's saved wconfigs, return is as given.
 
Otherwise return nil."
 
  (let ((wconfigs (wg-workgroup-saved-wconfigs workgroup)))
 
    (etypecase wconfig-or-name
 
    (cl-etypecase wconfig-or-name
 
      (wg-wconfig (car (memq wconfig-or-name wconfigs)))
 
      (string (wg-find wconfig-or-name wconfigs
 
      (string (cl-find wconfig-or-name wconfigs
 
                    :key 'wg-wconfig-name
 
                    :test 'string=)))))
 

	
 
@@ -1096,9 +1095,9 @@ WORKGROUP's saved wconfigs, replace it."
 
    (unless name (error "Attempt to save a nameless wconfig"))
 
    (setf (wg-workgroup-modified workgroup) t)
 
    (wg-asetf (wg-workgroup-saved-wconfigs workgroup)
 
              (cons wconfig (wg-remove* name it
 
                                     :key 'wg-wconfig-name
 
                                     :test 'string=)))))
 
              (cons wconfig (cl-remove name it
 
                                       :key 'wg-wconfig-name
 
                                       :test 'string=)))))
 

	
 
(defun wg-workgroup-kill-saved-wconfig (workgroup wconfig-or-name)
 
  "Delete WCONFIG-OR-NAME from WORKGROUP's saved wconfigs.
 
@@ -1135,9 +1134,9 @@ BUFFER nil defaults to `current-buffer'."
 
(defun wg-workgroup-gc-buf-uids (workgroup)
 
  "Remove buf uids from WORKGROUP that have no referent in `wg-buf-list'."
 
  (wg-asetf (wg-workgroup-strong-buf-uids workgroup)
 
            (wg-remove-if-not 'wg-find-buf-by-uid it)
 
            (cl-remove-if-not 'wg-find-buf-by-uid it)
 
            (wg-workgroup-weak-buf-uids workgroup)
 
            (wg-remove-if-not 'wg-find-buf-by-uid it)))
 
            (cl-remove-if-not 'wg-find-buf-by-uid it)))
 

	
 
(defun wg-gc-buf-uids ()
 
  "Remove from all workgroups those buf uids that have no referent in `wg-buf-list'."
 
@@ -1152,7 +1151,7 @@ BUFFER nil defaults to `current-buffer'."
 

	
 
(defun wg-wtree-unique-buf-uids (wtree)
 
  "Return a list of the unique buf uids of all wins in wtree."
 
  (wg-remove-duplicates (wg-wtree-buf-uids wtree) :test 'string=))
 
  (cl-remove-duplicates (wg-wtree-buf-uids wtree) :test 'string=))
 

	
 
(defun wg-wconfig-buf-uids (wconfig)
 
  "Return WCONFIG's wtree's `wg-wtree-buf-uids'."
 
@@ -1164,19 +1163,19 @@ BUFFER nil defaults to `current-buffer'."
 

	
 
(defun wg-workgroup-saved-wconfigs-buf-uids (workgroup)
 
  "Return a new list of all unique buf uids in WORKGROUP's base wconfig."
 
  (wg-reduce 'wg-string-list-union
 
  (cl-reduce 'wg-string-list-union
 
          (wg-workgroup-saved-wconfigs workgroup)
 
          :key 'wg-wconfig-buf-uids))
 

	
 
(defun wg-workgroup-all-wconfig-buf-uids (workgroup)
 
  "Return a new list of all unique buf uids in WORKGROUP's wconfigs."
 
  (wg-union (wg-workgroup-base-wconfig-buf-uids workgroup)
 
  (cl-union (wg-workgroup-base-wconfig-buf-uids workgroup)
 
         (wg-workgroup-saved-wconfigs-buf-uids workgroup)
 
         :test 'string=))
 

	
 
(defun wg-workgroup-all-buf-uids (workgroup)
 
  "Return a new list of all unique buf uids in WORKGROUP."
 
  (wg-reduce 'wg-string-list-union
 
  (cl-reduce 'wg-string-list-union
 
          (list (wg-workgroup-base-wconfig-buf-uids workgroup)
 
                (wg-workgroup-saved-wconfigs-buf-uids workgroup)
 
                (if wg-restore-associated-buffers
 
@@ -1186,7 +1185,7 @@ BUFFER nil defaults to `current-buffer'."
 
(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'."
 
  (wg-reduce 'wg-string-list-union
 
  (cl-reduce 'wg-string-list-union
 
          (wg-session-workgroup-list (or session (wg-current-session)))
 
          :key 'wg-workgroup-all-buf-uids))
 

	
 
@@ -1198,7 +1197,7 @@ BUFFER-LIST nil defaults to `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'."
 
  (wg-union (wg-session-all-buf-uids session)
 
  (cl-union (wg-session-all-buf-uids session)
 
         (wg-buffer-list-all-uids buffer-list)
 
         :test 'string=))
 

	
 
@@ -1206,7 +1205,7 @@ BUFFER-LIST nil defaults to `buffer-list'."
 
  "gc bufs from `wg-buf-list' that are no longer needed."
 
  (let ((all-buf-uids (wg-all-buf-uids)))
 
    (wg-asetf (wg-buf-list)
 
              (wg-remove-if-not (lambda (uid) (member uid all-buf-uids)) it
 
              (cl-remove-if-not (lambda (uid) (member uid all-buf-uids)) it
 
                             :key 'wg-buf-uid))))
 

	
 

	
 
@@ -1229,7 +1228,7 @@ BUFFER-LIST nil defaults to `buffer-list'."
 
(defun wg-session-uids-consistent-p ()
 
  "Return t if there are no duplicate bufs or buf uids in the wrong places,
 
nil otherwise."
 
  (and (wg-every (lambda (wg)
 
  (and (cl-every (lambda (wg)
 
                (not (wg-dups-p (wg-workgroup-associated-buf-uids wg)
 
                                :test 'string=)))
 
              (wg-workgroup-list))
 
@@ -1277,7 +1276,7 @@ Also delete all references to it by `wg-workgroup-state-table',
 
  "Add WORKGROUP to `wg-workgroup-list' at INDEX or the end.
 
If a workgroup with the same name exists, overwrite it."
 
  (wg-awhen (wg-find-workgroup-by :name (wg-workgroup-name workgroup) t)
 
    (unless index (setq index (wg-position it (wg-workgroup-list-or-error))))
 
    (unless index (setq index (cl-position it (wg-workgroup-list-or-error))))
 
    (wg-delete-workgroup it))
 
  (wg-asetf (wg-workgroup-list)
 
            (wg-insert-before workgroup it (or index (length it))))
 
@@ -1385,7 +1384,7 @@ for display by `other-buffer' in the current workgroup."
 

	
 
(defun wg-mode-line-buffer-association-indicator (workgroup)
 
  "Return a string indicating `current-buffer's association-type in WORKGROUP."
 
  (case (wg-workgroup-bufobj-association-type workgroup (current-buffer))
 
  (cl-case (wg-workgroup-bufobj-association-type workgroup (current-buffer))
 
    (strong wg-mode-line-decor-strongly-associated)
 
    (weak wg-mode-line-decor-weakly-associated)
 
    (otherwise wg-mode-line-decor-unassociated)))
 
@@ -1429,7 +1428,7 @@ for display by `other-buffer' in the current workgroup."
 
  (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 (wg-position 'mode-line-position mode-line-format) 10)))
 
          (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))))
 
@@ -1498,7 +1497,7 @@ Also save the msg to `wg-last-message'."
 
;;     (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 (incf i))))
 
;;         (wg-doconcat (elt list div) (funcall elt-fn elt (cl-incf i))))
 
;;       (:brace wg-list-display-decor-right-brace))))
 

	
 
(defcustom wg-display-max-lines 1
 
@@ -1518,7 +1517,7 @@ Also save the msg to `wg-last-message'."
 
          (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 (incf i))))
 
              (wg-doconcat (elt list div) (funcall elt-fn elt (cl-incf i))))
 
            (:brace wg-list-display-decor-right-brace)))
 
    ;; (subseq str 0 wwidth)
 
    ))
 
@@ -1606,14 +1605,14 @@ current and previous workgroups."
 
  "Return a new, unique, default workgroup name."
 
  (let ((names (wg-workgroup-names t)) (index -1) result)
 
    (while (not result)
 
      (let ((new-name (format "wg%s" (incf index))))
 
      (let ((new-name (format "wg%s" (cl-incf index))))
 
        (unless (member new-name names)
 
          (setq result new-name))))
 
    result))
 

	
 
(defun wg-unique-workgroup-name-p (new-name)
 
  "Return t if NEW-NAME is unique in `wg-workgroup-list', nil otherwise."
 
  (wg-every (lambda (existing-name) (not (equal new-name existing-name)))
 
  (cl-every (lambda (existing-name) (not (equal new-name existing-name)))
 
         (wg-workgroup-names t)))
 

	
 
(defun wg-read-new-workgroup-name (&optional prompt)
src/workgroups-ido.el
Show inline comments
 
@@ -3,20 +3,23 @@
 
;;; Code:
 

	
 
(require 'workgroups-variables)
 
(require 'iswitchb)
 
(require 'ido)
 

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

	
 
(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
 
    (case (let (workgroups-mode) (command-remapping 'switch-to-buffer))
 
    (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."
 
  (case (or mode (wg-read-buffer-mode))
 
  (cl-case (or mode (wg-read-buffer-mode))
 
    (ido 'ido-read-buffer)
 
    (iswitchb 'iswitchb-read-buffer)
 
    (fallback (lambda (prompt &optional default require-match)
 
@@ -27,7 +30,7 @@
 
(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."
 
  (ecase (wg-read-buffer-mode)
 
  (cl-ecase (wg-read-buffer-mode)
 
    (ido
 
     (ido-completing-read prompt choices pred require-match
 
                          initial-input history default))
 
@@ -42,7 +45,7 @@
 

	
 
(defun wg-current-matches (&optional read-buffer-mode)
 
  "Return READ-BUFFER-MODE's current matches."
 
  (ecase (or read-buffer-mode (wg-read-buffer-mode))
 
  (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))))
 
@@ -53,7 +56,7 @@
 

	
 
(defun wg-set-current-matches (match-list &optional read-buffer-mode)
 
  "Set READ-BUFFER-MODE's current matches, and flag a rescan."
 
  (case (or read-buffer-mode (wg-read-buffer-mode))
 
  (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)))
 
@@ -91,7 +94,7 @@ DEFAULT non-nil specifies the first completion candidate."
 
      (call-interactively (wg-prior-mapping workgroups-mode command))
 
    (wg-with-buffer-list-filters command
 
      (let ((wg-buffer-internal-default-buffer default))
 
        (ecase (wg-read-buffer-mode)
 
        (cl-ecase (wg-read-buffer-mode)
 
          (ido
 
           (ido-buffer-internal
 
            (wg-aget wg-ido-method-translations command) nil
src/workgroups-pickel.el
Show inline comments
 
@@ -26,7 +26,7 @@
 
;;
 
;;; Code:
 

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

	
 
@@ -86,12 +86,12 @@
 
  (unless (memq (type-of obj) wg-pickel-pickelable-types)
 
    (signal 'wg-pickel-unpickelable-type-error
 
            (format "Can't pickel objects of type: %S" (type-of obj))))
 
  (typecase obj
 
  (cl-typecase obj
 
    (cons
 
     (wg-pickelable-or-error (car obj))
 
     (wg-pickelable-or-error (cdr obj)))
 
    (vector
 
     (map nil 'wg-pickelable-or-error obj))
 
     (cl-map nil 'wg-pickelable-or-error obj))
 
    (hash-table
 
     (wg-dohash (key value obj)
 
       (wg-pickelable-or-error key)
 
@@ -140,8 +140,8 @@
 
    (dflet
 
     ((inner (obj)
 
           (unless (gethash obj binds)
 
              (puthash obj (incf id) binds)
 
              (case (type-of obj)
 
              (puthash obj (cl-incf id) binds)
 
              (cl-case (type-of obj)
 
                (cons
 
                 (inner (car obj))
 
                 (inner (cdr obj)))
 
@@ -362,7 +362,7 @@ parameters and the parameters of all its workgroups."
 
      (when (wg-session-parameters copy)
 
        (wg-asetf (wg-session-parameters copy) (wg-pickel copy)))
 
      (wg-asetf (wg-session-workgroup-list copy)
 
                (mapcar 'wg-pickel-workgroup-parameters it))
 
                (cl-mapcar 'wg-pickel-workgroup-parameters it))
 
      copy))
 

	
 
  (defun wg-unpickel-session-parameters (session)
 
@@ -372,7 +372,7 @@ parameters and the parameters of all its workgroups."
 
      (when (wg-session-parameters copy)
 
        (wg-asetf (wg-session-parameters copy) (wg-unpickel copy)))
 
      (wg-asetf (wg-session-workgroup-list copy)
 
                (mapcar 'wg-unpickel-workgroup-parameters it))
 
                (cl-mapcar 'wg-unpickel-workgroup-parameters it))
 
      copy))
 

	
 
(provide 'workgroups-pickel)
src/workgroups-restore.el
Show inline comments
 
@@ -111,10 +111,10 @@ a wtree."
 
(defun wg-restore-window-tree-helper (w)
 
  "Recursion helper for `wg-restore-window-tree'."
 
  (if (wg-wtree-p w)
 
      (loop with dir = (wg-wtree-dir w)
 
            for (win . rest) on (wg-wtree-wlist w)
 
            do (when rest (split-window nil (wg-w-size win dir) (not dir)))
 
            do (wg-restore-window-tree-helper win))
 
      (cl-loop with dir = (wg-wtree-dir w)
 
               for (win . rest) on (wg-wtree-wlist w)
 
               do (when rest (split-window nil (wg-w-size win dir) (not dir)))
 
               do (wg-restore-window-tree-helper win))
 
    (wg-restore-window w)
 
    (when (wg-win-selected w)
 
      (setq wg-window-tree-selected-window (selected-window)))
src/workgroups-specialbufs.el
Show inline comments
 
@@ -7,7 +7,7 @@
 
;;
 
;;; Code:
 

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

	
 
@@ -472,11 +472,11 @@ You can get these commands using `wg-get-org-agenda-view-commands'."
 

	
 
(defun wg-deserialize-buffer-local-variables (buf)
 
  "Restore BUF's buffer local variables in `current-buffer'."
 
  (loop for ((var . val) . rest) on (wg-buf-local-vars buf)
 
        do (wg-awhen (assq var wg-buffer-local-variables-alist)
 
             (wg-dbind (var ser des) it
 
               (if des (funcall des val)
 
                 (set var val))))))
 
  (cl-loop for ((var . val) . rest) on (wg-buf-local-vars buf)
 
           do (wg-awhen (assq var wg-buffer-local-variables-alist)
 
                (wg-dbind (var ser des) it
 
                  (if des (funcall des val)
 
                    (set var val))))))
 

	
 
(provide 'workgroups-specialbufs)
 
;;; workgroups-specialbufs.el ends here
src/workgroups-utils-basic.el
Show inline comments
 
@@ -28,7 +28,6 @@
 
;;
 
;;; Code:
 

	
 
(require 'dflet)
 
(require 'workgroups-compat)
 

	
 
;;; utils used in macros
 
@@ -36,13 +35,13 @@
 
(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 (wg-gensym))) syms)) ,@body))
 
  `(let (,@(mapcar (lambda (sym) `(,sym (cl-gensym))) syms)) ,@body))
 

	
 
(defmacro wg-dbind (args expr &rest body)
 
  "Bind the variables in ARGS to the result of EXPR and execute BODY.
 
Abbreviation of `destructuring-bind'."
 
  (declare (indent 2))
 
  `(destructuring-bind ,args ,expr ,@body))
 
  `(cl-destructuring-bind ,args ,expr ,@body))
 

	
 
(defun wg-partition (list &optional n step)
 
  "Return list of N-length sublists of LIST, offset by STEP.
 
@@ -176,15 +175,15 @@ into a var, like so: (a (b c) . rest)
 

	
 
(defmacro wg-eager-or (&rest conditions)
 
  "Evaluate all CONDITIONS.  Return the first non-nil return value."
 
  (let ((syms (mapcar (lambda (x) (wg-gensym)) conditions)))
 
    `(let ,(wg-mapcar* 'list syms conditions)
 
  (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) (wg-gensym)) conditions)))
 
    `(let ,(wg-mapcar* 'list syms conditions)
 
  (let ((syms (mapcar (lambda (x) (cl-gensym)) conditions)))
 
    `(let ,(cl-mapcar 'list syms conditions)
 
       (and ,@syms))))
 

	
 

	
 
@@ -227,7 +226,7 @@ Cribbed from `org-id-b36-to-int-one-digit'."
 
                      (setq i (/ i base))))
 
      (add-digit)
 
      (while (> i 0) (add-digit))
 
      (setq b36 (map 'string 'identity b36))
 
      (setq b36 (cl-map 'string 'identity b36))
 
      (if (not length) b36
 
        (concat (make-string (max 0 (- length (length b36))) ?0) b36)))))
 

	
 
@@ -249,13 +248,13 @@ Cribbed from `org-id-b36-to-int'."
 
  "If ITEM is a `member*' of SEQ-PLACE, remove it from SEQ-PLACE and return t.
 
Otherwise return nil.  KEYS can be any keywords accepted by `remove*'."
 
  `(> (length ,seq-place)
 
      (length (setf ,seq-place (wg-remove* ,item ,seq-place ,@keys)))))
 
      (length (setf ,seq-place (cl-remove ,item ,seq-place ,@keys)))))
 

	
 
(defmacro wg-pushnew-p (item seq-place &rest keys)
 
  "If ITEM is not a `member' of SEQ-PLACE, push it to SEQ-PLACE and return t.
 
Otherwise return nil.  KEYS can be any keyword args accepted by `pushnew'."
 
  `(< (length ,seq-place)
 
      (length (pushnew ,item ,seq-place ,@keys))))
 
      (length (cl-pushnew ,item ,seq-place ,@keys))))
 

	
 
(defun wg-last1 (list)
 
  "Return the last element of LIST."
 
@@ -300,7 +299,7 @@ length is even, the first elt is left nearer the front."
 

	
 
(defun wg-insert-after (elt list index)
 
  "Insert ELT into LIST after INDEX."
 
  (let ((new-list (wg-copy-list list)))
 
  (let ((new-list (cl-copy-list list)))
 
    (push elt (cdr (nthcdr index new-list)))
 
    new-list))
 

	
 
@@ -312,7 +311,7 @@ length is even, the first elt is left nearer the front."
 
(defun wg-move-elt (elt list index &rest keys)
 
  "Move ELT before INDEX in LIST.
 
KEYS is passed to `remove*'."
 
  (wg-insert-before elt (apply 'wg-remove* elt list keys) index))
 
  (wg-insert-before elt (apply 'cl-remove elt list keys) index))
 

	
 
(defun wg-cyclic-nth (list n)
 
  "Return the Nth element of LIST, modded by the length of list."
 
@@ -320,21 +319,21 @@ KEYS is passed to `remove*'."
 

	
 
(defun wg-cyclic-offset-elt (elt list n)
 
  "Cyclically offset ELT's position in LIST by N."
 
  (wg-when-let ((pos (wg-position elt list)))
 
  (wg-when-let ((pos (cl-position elt list)))
 
    (wg-move-elt elt list (mod (+ n pos) (length list)))))
 

	
 
(defun wg-cyclic-nth-from-elt (elt list n &rest keys)
 
  "Return the elt in LIST N places cyclically from ELT.
 
If ELT is not present is LIST, return nil.
 
KEYS is passed to `position'."
 
  (wg-when-let ((pos (apply 'wg-position elt list keys)))
 
  (wg-when-let ((pos (apply 'cl-position elt list keys)))
 
    (wg-cyclic-nth list (+ pos n))))
 

	
 
(defun wg-util-swap (elt1 elt2 list)
 
  "Return a copy of LIST with ELT1 and ELT2 swapped.
 
Return nil when ELT1 and ELT2 aren't both present."
 
  (wg-when-let ((p1 (wg-position elt1 list))
 
                (p2 (wg-position elt2 list)))
 
  (wg-when-let ((p1 (cl-position elt1 list))
 
                (p2 (cl-position elt2 list)))
 
    (wg-move-elt elt1 (wg-move-elt elt2 list p1) p2)))
 

	
 
(defun wg-dups-p (list &rest keys)
 
@@ -345,14 +344,14 @@ Keywords supported: :test :key
 
\(fn LIST [KEYWORD VALUE]...)"
 
  (let ((test (or (plist-get keys :test) 'eq))
 
        (key (or (plist-get keys :key) 'identity)))
 
    (loop for (elt . rest) on list
 
          for elt = (funcall key elt)
 
          when (wg-find elt rest :test test :key key) return elt)))
 
    (cl-loop for (elt . rest) on list
 
             for elt = (funcall key elt)
 
             when (cl-find elt rest :test test :key key) return elt)))
 

	
 
(defun wg-string-list-union (&optional list1 list2)
 
  "Return the `union' of LIST1 and LIST2, using `string=' as the test.
 
This only exists to get rid of duplicate lambdas in a few reductions."
 
  (wg-union list1 list2 :test 'string=))
 
  (cl-union list1 list2 :test 'string=))
 

	
 

	
 

	
 
@@ -461,14 +460,14 @@ Note that this won't make VAR buffer-local if it isn't already."
 

	
 
(defun wg-interesting-buffers ()
 
  "Return a list of only the interesting buffers in `buffer-list'."
 
  (wg-remove-if (lambda (bname) (string-match "^ " bname))
 
             (buffer-list) :key 'buffer-name))
 
  (cl-remove-if (lambda (bname) (string-match "^ " bname))
 
                (buffer-list) :key 'buffer-name))
 

	
 
(defun wg-get-first-buffer-matching-regexp (regexp &optional buffer-list)
 
  "Return the first buffer in BUFFER-LIST with a name matching REGEXP.
 
BUFFER-LIST should contain buffer objects and/or buffer names."
 
  (wg-find regexp (or buffer-list (buffer-list))
 
        :test 'string-match :key 'wg-buffer-name))
 
  (cl-find regexp (or buffer-list (buffer-list))
 
           :test 'string-match :key 'wg-buffer-name))
 

	
 

	
 

	
 
@@ -525,7 +524,7 @@ options."
 
      ;; too, but it annoyingly requires inclusion of the function's arglist,
 
      ;; which gets ugly.
 
      `(eval-and-compile
 
         (defstruct ,(if (symbolp name-form) prefixed-name
 
         (cl-defstruct ,(if (symbolp name-form) prefixed-name
 
                       `(,prefixed-name ,@(cdr name-form)))
 
           ,@slot-defs)
 
         ,@(rebind "make")
 
@@ -600,7 +599,7 @@ ARGS are `read-from-minibuffer's args, after PROMPT."
 
  "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-seq string)))
 
        (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)
 
@@ -654,8 +653,8 @@ This needs to be a macro to allow specification of a setf'able place."
 

	
 
(defun wg-b36-to-time (b36)
 
  "Parse the time from UID."
 
  (loop for i from 0 to 8 by 4
 
        collect (wg-b36-to-int (wg-subsec b36 i (+ i 4)))))
 
  (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)
src/workgroups-variables.el
Show inline comments
 
@@ -899,7 +899,7 @@ new workgroup during a switch.")
 
  "`defface' wrapper adding a lookup key used by `wg-fontify'."
 
  (declare (indent 2))
 
  `(progn
 
     (pushnew (cons ,key ',face) wg-face-abbrevs :test #'equal)
 
     (cl-pushnew (cons ,key ',face) wg-face-abbrevs :test #'equal)
 
     (defface ,face ,spec ,doc ,@args)))
 

	
 
(wg-defface wg-current-workgroup-face :cur
src/workgroups2.el
Show inline comments
 
@@ -83,14 +83,14 @@
 
;;
 
;;; Code:
 

	
 
(require 'dflet)
 
(require 'workgroups-compat)
 
(require 'workgroups-utils-basic)
 
(require 'workgroups-pickel)
 

	
 
(eval-when-compile ;; bytecomp warnings begone!
 
  (require 'ido nil t)
 
  (require 'iswitchb nil t))
 
(require 'cl-lib)
 
(eval-when-compile
 
  (require 'ido)
 
  (require 'iswitchb))
 

	
 
(require 'workgroups-variables)
 
(require 'workgroups-functions)
 
@@ -217,8 +217,8 @@ Called when `workgroups-mode' is turned off."
 
  "Add Workgroups' minor-mode entries.
 
Adds entries to `minor-mode-list', `minor-mode-alist' and
 
`minor-mode-map-alist'."
 
  (pushnew 'workgroups-mode minor-mode-list)
 
  (pushnew '(workgroups-mode " wg") minor-mode-alist :test 'equal)
 
  (cl-pushnew 'workgroups-mode minor-mode-list)
 
  (cl-pushnew '(workgroups-mode " wg") 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)
0 comments (0 inline, 0 general)