Changeset - 69ab704a7974
[Not reviewed]
0 5 0
Sergey Pashinin - 11 years ago 2014-08-23 16:57:04
sergey@pashinin.com
wg-when-let replaced
5 files changed with 19 insertions and 38 deletions:
0 comments (0 inline, 0 general)
src/workgroups-advice.el
Show inline comments
 
@@ -190,8 +190,8 @@ See `wg-buffer-auto-association' for allowable values of ASSOC."
 
  "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))
 
                  (b (get-buffer buffer)))
 
    (-when-let* ((wg (wg-current-workgroup t frame))
 
                 (b (get-buffer buffer)))
 
      (unless (or (wg-workgroup-bufobj-association-type wg buffer)
 
                  (member wg wg-deactivation-list)
 
                  (member (buffer-name b) wg-associate-blacklist)
src/workgroups-buf.el
Show inline comments
 
@@ -50,7 +50,7 @@ When a buffer can't be restored, when creating a blank wg."
 

	
 
(defun wg-restore-existing-buffer (buf &optional switch)
 
  "Return existing buffer from BUF and maybe SWITCH to it."
 
  (wg-when-let ((b (wg-find-buf-in-buffer-list buf (wg-buffer-list-emacs))))
 
  (-when-let (b (wg-find-buf-in-buffer-list buf (wg-buffer-list-emacs)))
 
    (if switch (switch-to-buffer b t))
 
    (with-current-buffer b
 
      (wg-set-buffer-uid-or-error (wg-buf-uid buf))
 
@@ -60,7 +60,7 @@ When a buffer can't be restored, when creating a blank wg."
 
  "Restore BUF by finding its file and maybe SWITCH to it.
 
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-let ((file-name (wg-buf-file-name buf)))
 
  (let ((file-name (wg-buf-file-name buf)))
 
    (when (and file-name
 
               (or wg-restore-remote-buffers
 
@@ -94,7 +94,7 @@ If BUF's file doesn't exist, call `wg-restore-default-buffer'"
 

	
 
(defun wg-restore-special-buffer (buf &optional switch)
 
  "Restore a buffer BUF with DESERIALIZER-FN and maybe SWITCH to it."
 
  (wg-when-let
 
  (-when-let*
 
      ((special-data (wg-buf-special-data buf))
 
       (buffer (save-window-excursion
 
                 (condition-case err
 
@@ -275,9 +275,9 @@ Currently only sets BUFFER's `wg-buffer-uid' to nil."
 
  "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)))
 
    (-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))))))
 

	
src/workgroups-utils-basic.el
Show inline comments
 
@@ -7,6 +7,7 @@
 

	
 
;;; utils used in macros
 

	
 
(require 'dash)
 
(require 'cl-lib)
 
(require 'anaphora)
 
(require 'workgroups-faces)
 
@@ -37,16 +38,6 @@ Iterative to prevent stack overflow."
 

	
 
;;; bindings
 

	
 
(defmacro wg-when-let (binds &rest body)
 
  "Like `let*' but when all BINDS are non-nil - eval BODY."
 
  (declare (indent 1))
 
  (wg-dbind (bind . binds) binds
 
    (when (consp bind)
 
      `(let (,bind)
 
         (when ,(car bind)
 
           ,(if (not binds) `(progn ,@body)
 
              `(wg-when-let ,binds ,@body)))))))
 

	
 
(defmacro wg-when-boundp (symbols &rest body)
 
  "When all SYMBOLS are bound, `eval' BODY."
 
  (declare (indent 1))
 
@@ -187,17 +178,6 @@ Otherwise return nil.  KEYS can be any keyword args accepted by `pushnew'."
 
    (dotimes (i (- end start) (nreverse accum))
 
      (push (+ start i) accum))))
 

	
 
(defun wg-rotate-list (list &optional offset)
 
  "Rotate LIST by OFFSET.  Positive OFFSET rotates left, negative right."
 
  (when list
 
    (let ((split (mod (or offset 1) (length list))))
 
      (append (nthcdr split list) (-take split list)))))
 

	
 
(defun wg-center-rotate-list (list)
 
  "Rotate LIST so it's first elt is in the center.  When LIST's
 
length is even, the first elt is left nearer the front."
 
  (wg-rotate-list list (- (/ (1- (length list)) 2))))
 

	
 
(defun wg-insert-after (elt list index)
 
  "Insert ELT into LIST after INDEX."
 
  (let ((new-list (cl-copy-list list)))
 
@@ -220,21 +200,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 (cl-position elt list)))
 
  (-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 'cl-position elt list keys)))
 
  (-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 (cl-position elt1 list))
 
                (p2 (cl-position elt2 list)))
 
  (-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)
src/workgroups-wconfig.el
Show inline comments
 
@@ -80,8 +80,8 @@ FRAME is deleted, so we don't lose its state."
 
(defun wg-wconfig-restore-frame-position (wconfig &optional frame)
 
  "Use WCONFIG to restore FRAME's position.
 
If frame is nil then `selected-frame'."
 
  (wg-when-let ((left (wg-wconfig-left wconfig))
 
                (top (wg-wconfig-top wconfig)))
 
  (-when-let* ((left (wg-wconfig-left wconfig))
 
               (top (wg-wconfig-top wconfig)))
 
    ;; Check that arguments are integers
 
    ;; Problem: https://github.com/pashinin/workgroups2/issues/15
 
    (if (and (integerp left)
src/workgroups-workgroup.el
Show inline comments
 
@@ -2,6 +2,7 @@
 
;;; Commentary:
 
;;; Code:
 

	
 
(require 'dash)
 
(require 'ring)
 
(require 'workgroups-wconfig)
 
(require 'workgroups-minibuffer)
 
@@ -161,8 +162,8 @@ WORKGROUP's saved wconfigs, replace it."
 
(defun wg-workgroup-kill-saved-wconfig (workgroup wconfig-or-name)
 
  "Delete WCONFIG-OR-NAME from WORKGROUP's saved wconfigs.
 
WCONFIG-OR-NAME is resolved with `wg-workgroup-get-saved-wconfig'."
 
  (wg-when-let ((wconfig (wg-workgroup-get-saved-wconfig
 
                          workgroup wconfig-or-name)))
 
  (-when-let (wconfig (wg-workgroup-get-saved-wconfig
 
                       workgroup wconfig-or-name))
 
    (wg-asetf (wg-workgroup-saved-wconfigs workgroup) (remq wconfig it)
 
              (wg-workgroup-modified workgroup) t)))
 

	
 
@@ -777,7 +778,7 @@ Added to `post-command-hook'."
 
         wg-window-configuration-changed         ;; When the window config has changed,
 
         wg-undoify-window-configuration-change  ;; and undoification is still on for the current command
 
         (wg-minibuffer-inactive-p))             ;; and the change didn't occur while the minibuffer is active,
 
    (wg-when-let ((workgroup (wg-current-workgroup t)))  ;; and there's a current workgroup,
 
    (-when-let (workgroup (wg-current-workgroup t))  ;; and there's a current workgroup,
 
      ;; add the current wconfig to that workgroup's undo list:
 
      (wg-add-wconfig-to-undo-list workgroup (wg-current-wconfig))))
 
  ;; Reset all flags no matter what:
0 comments (0 inline, 0 general)