Domanda

I use many workgroups in my workflow (package workgroups or workgroups2). If I switch to some workgroup and try to winner-undo I get window configuration from previous workgroup. Can I use separate winner-undo history for each workgroup?

My workgroups

È stato utile?

Soluzione

I've just pushed a commit in workgroups2.
Now winner-undo, winner-redo commands are remapped to workgroups' commands which do the same thing as winner but for each workgroup.

Altri suggerimenti

Upd. When I tested workgroups2 undo functionality last time, I made a mistake and misunderstood the behaviour of wg-undo-wconfig-change (wg-redo-wconfig-change). So, workgroups2 just has the ability to save the history of each workgroup like winner-mode does it. This solution can be used for workgroups package only.

I wrote this:

(defvar wg-winner-vars nil)
(defvar wg-winner-hash nil)

(setq wg-winner-vars '(winner-ring-alist
               winner-currents
               winner-point-alist
               winner-undone-data
               winner-undo-counter
               winner-pending-undo-ring))

(setq wg-winner-hash (make-hash-table :test 'equal))

(defun wg-winner-put (winner-name)
  (let ((wg (ignore-errors (wg-name (wg-current-workgroup)))))
    (if wg
    (puthash (list wg winner-name) (eval winner-name) wg-winner-hash))))

(defun wg-winner-get (winner-name)
  (let ((wg (ignore-errors (wg-name (wg-current-workgroup)))))
    (if wg
    (eval `(setq ,winner-name (gethash '(,wg ,winner-name) wg-winner-hash))))))

(defun wg-winner-save ()
  (if winner-mode
      (progn
    (winner-mode -1)
    (defun wg-winner-mode-restore ()
      (winner-mode 1)))
    (defun wg-winner-mode-restore ()))
  (mapcar 'wg-winner-put wg-winner-vars))

(defun wg-winner-load ()
  (mapcar 'wg-winner-get wg-winner-vars)
  (wg-winner-mode-restore))

(defadvice wg-switch-to-workgroup (before wg-winner-before activate)
  (wg-winner-save))

(defadvice wg-switch-to-workgroup (after wg-winner-after activate)
  (wg-winner-load))

If you're happy to write the elisp:

winner-ring-alist is an alist of window configuration rings keyed by frame (i.e. a ring of window configs per frame).

I would suggest you define a new alist keyed by frame and by the workgroup identifier (whatever that is), in which you can store the workgroup-specific winner config ring for each frame.

I imagine there's a "switch workgroup" hook you can then use to write the current frame's config ring to your alist (for the workgroup you're switching from), and then replace the ring for the current frame with your stored config for the workground you're switching to.

There's probably not much more to it. As long as winner sees the data it needs, it'll probably "just work".

If it works nicely, consider contributing the code back to the workgroups project.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top