unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Joshua Studen <joshua.studen@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: RE: Frame numbering
Date: Sat, 19 Apr 2014 12:42:14 -0700 (PDT)	[thread overview]
Message-ID: <b4bd1621-6559-43c9-8678-d7f4a22f13a0@default> (raw)
In-Reply-To: <CAFR0EmkMKrOgZJwrjiw+HmysXDTk5Lg3YWyt4SPYrzL8wS86kw@mail.gmail.com>

>> 1. `C-x 5 o' cycles among the available frames.  This is true even
>> if you use Emacs in a terminal (i.e., without a graphic display) -
>> see the Emacs manual, node `Non-Window Terminals'.
>> 
>> 2. Command `select-frame-by-name' raises and selects a frame by name,
>> providing completion.  Again, this works also without a graphic display.
>> Frame names in a terminal are simple by default: FN1, FN2, etc.
>> Bind the command to a key, e.g., `C-a' as you suggested.  Then
>> `C-a TAB 3' takes you to frame FN3.
>
> Number 1 is what I do now, it's just a lot a bit of a slow-down to
> have to do it multiple times if I have multiple frames.
> 
> #2 is very close. The ONLY issue is that I use emacs both via GUI
> locally and on a remote machine, I do emacs --daemon.  When I leave
> the remote session, and come back and create a new Emacs client,
> the frame numbers do NOT start back at F1, I need a combination of
> your #2 and the suggested M-x set-frame-name. Maybe next emacs,
> there will be a way to set a frame name :).

FWIW, here is some code that will give you numeric frame names.
Together with binding `select-frame-by-name' to a convenient key
it should give you much of what you want.

You can add `name-frame-numerically' to a hook, such as
`after-make-frame-functions', or put it on an idle timer, or whatever.

If the selected name does not have a numeric name (1,2,3...) then
`name-frame-numerically' renames it and any other frames with
non-numeric names.  Else it does nothing (including not renaming any
other frames).

(require 'cl-lib)

(defun frame-number (frame)
  "Return FRAME's number, or nil if its name is not a numeral 1,2,3..."
  (let ((num  (string-to-number (frame-parameter frame 'name))))
    (and (wholenump num)  (not (zerop num))  num)))

(defun name-frame-numerically (&optional frame frames)
  "Name FRAME (default, selected frame) to a numeral in 1,2,3...
If FRAME's name is already such a numeral, do nothing.
Else:
 Rename it to a numeral one greater than the max numeric frame name.
 Rename any other frames to numerals also."
  (interactive)
  (setq frame   (or frame   (selected-frame))
        frames  (or frames  (list frame)))
  (let ((onum  (frame-number frame))
        onums max)
    (unless onum
      (dolist (fr  (cl-set-difference (frame-list) frames))
        (unless (eq fr frame)
          (name-frame-numerically fr (cons fr frames))))
      (setq onums  (delq nil (mapcar #'frame-number (frame-list)))
            max    (if onums (apply #'max onums) 0))
      (modify-frame-parameters
       frame `((name ,@(number-to-string (1+ max))))))))

;; Just in case you want such a command.
(defun name-all-frames-numerically (&optional startover)
  "Rename all frames to numerals in 1,2,3...
With optional arg STARTOVER (prefix arg, interactively), rename all
starting over from 1.  Otherwise, numbering continues from the highest
existing frame number."
  (interactive "P")
  (when startover
    (dolist (fr  (frame-list))
      (modify-frame-parameters
       fr `((name ,@(format "a%s" (frame-parameter fr 'name)))))))
  (mapc #'name-frame-numerically (frame-list)))

;; Name frames when they are created.
;; (add-hook 'after-make-frame-functions 'name-frame-numerically)



  reply	other threads:[~2014-04-19 19:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-18 21:34 Frame numbering Joshua Studen
2014-04-19  1:07 ` Drew Adams
2014-04-19 14:39   ` Joshua Studen
2014-04-19 19:42     ` Drew Adams [this message]
     [not found]   ` <mailman.19880.1397918343.10748.help-gnu-emacs@gnu.org>
2014-04-20  8:18     ` Javier
2014-04-19  6:32 ` Eli Zaretskii
2014-04-19  8:17   ` Alan Schmitt
2014-04-19  8:42     ` Eli Zaretskii
2014-04-19 11:00       ` Alan Schmitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b4bd1621-6559-43c9-8678-d7f4a22f13a0@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=joshua.studen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).