unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* frameset-to-register
@ 2013-08-05  5:12 Juanma Barranquero
  2013-08-05 13:11 ` frameset-to-register Juanma Barranquero
  2013-08-05 20:35 ` frameset-to-register Drew Adams
  0 siblings, 2 replies; 8+ messages in thread
From: Juanma Barranquero @ 2013-08-05  5:12 UTC (permalink / raw)
  To: Emacs developers

This code adds a new frameset-to-register command.

Assuming that it is OK to install it, keybindings in the C-x r space
are scarce. I propose to bind it to C-x r F, which is already co-opted
by frame-configuration-to-register (via C-x r f) and seems mnemonic
enough.

   Juanma




=== modified file 'lisp/register.el'
--- lisp/register.el    2013-03-26 02:49:05 +0000
+++ lisp/register.el    2013-08-05 05:07:08 +0000
@@ -132,6 +132,20 @@
   ;; of point in the current buffer, so record that separately.
   (set-register register (list (current-frame-configuration) (point-marker))))

+(defun frameset-to-register (register &optional _arg)
+  "Store the current frameset in register REGISTER.
+Use \\[jump-to-register] to restore the frameset.
+Argument is a character, naming the register."
+  (interactive "cFrameset to register: \nP")
+  (set-register register
+               (list (frameset-save nil
+                                    :filters frameset-live-filter-alist
+                                    :properties '(:app register))
+                     ;; frameset-save does not include the value of point
+                     ;; in the current buffer, so record that separately.
+                     (frame-parameter nil 'frameset--id)
+                     (point-marker))))
+
 (defalias 'register-to-point 'jump-to-register)
 (defun jump-to-register (register &optional delete)
   "Move point to location stored in a register.
@@ -157,6 +171,18 @@
      ((and (consp val) (window-configuration-p (car val)))
       (set-window-configuration (car val))
       (goto-char (cadr val)))
+     ((and (consp val) (frameset-p (car val)))
+      (frameset-restore (car val)
+                       :filters frameset-live-filter-alist
+                       :reuse-frames t)
+      ;; At this point, cl-lib is loaded via frameset.el
+      (let ((frame (cl-find-if (lambda (f)
+                                (string= (frame-parameter f 'frameset--id)
+                                         (cadr val)))
+                              (frame-list))))
+       (when frame
+         (select-frame-set-input-focus frame)
+         (goto-char (nth 2 val)))))
      ((markerp val)
       (or (marker-buffer val)
          (error "That register's buffer no longer exists"))
@@ -269,6 +295,9 @@
      ((and (consp val) (frame-configuration-p (car val)))
       (princ "a frame configuration."))

+     ((and (consp val) (frameset-p (car val)))
+      (princ "a frameset."))
+
      ((and (consp val) (eq (car val) 'file))
       (princ "the file ")
       (prin1 (cdr val))



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: frameset-to-register
  2013-08-05  5:12 frameset-to-register Juanma Barranquero
@ 2013-08-05 13:11 ` Juanma Barranquero
  2013-08-05 20:35 ` frameset-to-register Drew Adams
  1 sibling, 0 replies; 8+ messages in thread
From: Juanma Barranquero @ 2013-08-05 13:11 UTC (permalink / raw)
  To: Emacs developers

On Mon, Aug 5, 2013 at 7:12 AM, Juanma Barranquero <lekktu@gmail.com> wrote:

> This code adds a new frameset-to-register command.

Or, a bit cleaner:

=== modified file 'lisp/register.el'
--- lisp/register.el    2013-03-26 02:49:05 +0000
+++ lisp/register.el    2013-08-05 12:50:18 +0000
@@ -132,6 +132,20 @@
   ;; of point in the current buffer, so record that separately.
   (set-register register (list (current-frame-configuration) (point-marker))))

+(defun frameset-to-register (register &optional _arg)
+  "Store the current frameset in register REGISTER.
+Use \\[jump-to-register] to restore the frameset.
+Argument is a character, naming the register."
+  (interactive "cFrameset to register: \nP")
+  (set-register register
+               (list (frameset-save nil
+                                    :filters frameset-live-filter-alist
+                                    :properties '(:app register))
+                     ;; frameset-save does not include the value of point
+                     ;; in the current buffer, so record that separately.
+                     (frameset-frame-id nil)
+                     (point-marker))))
+
 (defalias 'register-to-point 'jump-to-register)
 (defun jump-to-register (register &optional delete)
   "Move point to location stored in a register.
@@ -157,6 +171,14 @@
      ((and (consp val) (window-configuration-p (car val)))
       (set-window-configuration (car val))
       (goto-char (cadr val)))
+     ((and (consp val) (frameset-p (car val)))
+      (frameset-restore (car val)
+                       :filters frameset-live-filter-alist
+                       :reuse-frames t)
+      (let ((frame (frameset-locate-frame-id (cadr val))))
+       (when frame
+         (select-frame-set-input-focus frame)
+         (goto-char (nth 2 val)))))
      ((markerp val)
       (or (marker-buffer val)
          (error "That register's buffer no longer exists"))
@@ -269,6 +291,9 @@
      ((and (consp val) (frame-configuration-p (car val)))
       (princ "a frame configuration."))

+     ((and (consp val) (frameset-p (car val)))
+      (princ "a frameset."))
+
      ((and (consp val) (eq (car val) 'file))
       (princ "the file ")
       (prin1 (cdr val))



^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: frameset-to-register
  2013-08-05  5:12 frameset-to-register Juanma Barranquero
  2013-08-05 13:11 ` frameset-to-register Juanma Barranquero
@ 2013-08-05 20:35 ` Drew Adams
  2013-08-05 20:49   ` frameset-to-register Juanma Barranquero
  1 sibling, 1 reply; 8+ messages in thread
From: Drew Adams @ 2013-08-05 20:35 UTC (permalink / raw)
  To: Juanma Barranquero, Emacs developers

> This code adds a new frameset-to-register command.
> 
> Assuming that it is OK to install it, keybindings in the C-x r space
> are scarce. I propose to bind it to C-x r F, which is already co-opted
> by frame-configuration-to-register (via C-x r f) and seems mnemonic
> enough.

Why does this not just replace `frame-configuration-to-register', i.e.,
C-x r f?  What are the differences?  In particular, what, if anything,
does `frame-configuration-to-register' let you do that
`frameset-to-register' does not let you do?

I understand that a frameset is Lisp-readable, so it can be persisted.
But it's not clear why one would use `frame-configuration-to-register'
if `frameset-to-register' is now available. 

I can guess that `frame-configuration-to-register' might be quicker,
but what are the real, user-level differences that would mean that a
user might want both to be available (and bound to keys)?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: frameset-to-register
  2013-08-05 20:35 ` frameset-to-register Drew Adams
@ 2013-08-05 20:49   ` Juanma Barranquero
  2013-08-06 21:11     ` frameset-to-register Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Juanma Barranquero @ 2013-08-05 20:49 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs developers

On Mon, Aug 5, 2013 at 10:35 PM, Drew Adams <drew.adams@oracle.com> wrote:

> Why does this not just replace `frame-configuration-to-register', i.e.,
> C-x r f?  What are the differences?  In particular, what, if anything,
> does `frame-configuration-to-register' let you do that
> `frameset-to-register' does not let you do?

I don't know, and that's the point. I've used
frame-configuration-to-register all of perhaps ten times, eight or so
just to test something. I think it makes more sense to leave both
options and let the user choose.

> I understand that a frameset is Lisp-readable, so it can be persisted.

Caveat user. The frameset I'm using for frameset-to-register is not
really "Lisp-readable", because I've opted to filter out as few frame
parameters as possible. That means that non-readable parameters, like
buffer-list, are kept. Why? Because frameset-to-register, like
frame-configuration-to-register, is an in-session command, and keeping
links to live (or dead) objects provides a better in-session user
experience. If someone someday decides to save to disk the frameset
contained in a register, we'll have to add code to filter out
additional parameters (should be trivial, once the use case is clearly
defined).

> But it's not clear why one would use `frame-configuration-to-register'
> if `frameset-to-register' is now available.

Perhaps you don't want dead frames to come back to life.

> I can guess that `frame-configuration-to-register' might be quicker,
> but what are the real, user-level differences that would mean that a
> user might want both to be available (and bound to keys)?

You try and tell me ;-)

   J



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: frameset-to-register
  2013-08-05 20:49   ` frameset-to-register Juanma Barranquero
@ 2013-08-06 21:11     ` Stefan Monnier
  2013-08-08  0:49       ` frameset-to-register Juanma Barranquero
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2013-08-06 21:11 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Drew Adams, Emacs developers

> I don't know, and that's the point.

I think it's worth the try: i.e. make the change in `trunk' and see
if/when people start screaming.  The difference between the two should
be small enough that we can't expect average users to have to choose
between the two.  More sophisticated users can rebind the key if they want.


        Stefan



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: frameset-to-register
  2013-08-06 21:11     ` frameset-to-register Stefan Monnier
@ 2013-08-08  0:49       ` Juanma Barranquero
  0 siblings, 0 replies; 8+ messages in thread
From: Juanma Barranquero @ 2013-08-08  0:49 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Drew Adams, Emacs developers

On Tue, Aug 6, 2013 at 11:11 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> I think it's worth the try: i.e. make the change in `trunk' and see
> if/when people start screaming.

More testing and bug reports are very welcome anyway...

> The difference between the two should
> be small enough that we can't expect average users to have to choose
> between the two.

Oh, I suspect that we'll soon discover that the differences aren't that small.

Committed in revno:113748.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* frameset-to-register
@ 2014-02-12 22:59 Juanma Barranquero
  2014-02-13  0:34 ` frameset-to-register Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Juanma Barranquero @ 2014-02-12 22:59 UTC (permalink / raw)
  To: Emacs developers

I'd like to commit this small patch, which basically makes the output
of list-registers/view-register a bit more informative for framesets.

It's not a bug fix, but OTOH, frameset-to-register is a new feature by
itself and this is just making the feature a bit better.

OK to install, or do I wait for the unfreezing?

   J



=== modified file 'lisp/frameset.el'
--- lisp/frameset.el 2014-02-11 20:48:23 +0000
+++ lisp/frameset.el 2014-02-12 22:42:11 +0000
@@ -1223,6 +1223,16 @@
     (set-frame-selected-window frame window)
     (with-current-buffer buffer (goto-char position))))))))

+(defun frameset--print-register (data)
+  "Print basic info about frameset stored in DATA.
+Called from `list-registers' and `view-register'.  Internal use only."
+  (let* ((fs (aref data 0))
+ (ns (length (frameset-states fs))))
+    (princ (format "a frameset (%d frame%s, saved on %s)."
+   ns
+   (if (= 1 ns) "" "s")
+   (format-time-string "%c" (frameset-timestamp fs))))))
+
 ;;;###autoload
 (defun frameset-to-register (register)
   "Store the current frameset in register REGISTER.
@@ -1240,7 +1250,7 @@
  ;; in the current buffer, so record that separately.
  (frameset-frame-id nil)
  (point-marker))
- :print-func (lambda (_data) (princ "a frameset."))
+ :print-func #'frameset--print-register
  :jump-func #'frameset--jump-to-register)))

 (provide 'frameset)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: frameset-to-register
  2014-02-12 22:59 frameset-to-register Juanma Barranquero
@ 2014-02-13  0:34 ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-02-13  0:34 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

> OK to install, or do I wait for the unfreezing?

Let's wait for the unfreezing,


        Stefan



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-02-13  0:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-05  5:12 frameset-to-register Juanma Barranquero
2013-08-05 13:11 ` frameset-to-register Juanma Barranquero
2013-08-05 20:35 ` frameset-to-register Drew Adams
2013-08-05 20:49   ` frameset-to-register Juanma Barranquero
2013-08-06 21:11     ` frameset-to-register Stefan Monnier
2013-08-08  0:49       ` frameset-to-register Juanma Barranquero
  -- strict thread matches above, loose matches on Subject: below --
2014-02-12 22:59 frameset-to-register Juanma Barranquero
2014-02-13  0:34 ` frameset-to-register Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).