[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Frame numbering
RE: Frame numbering
Sat, 19 Apr 2014 12:42:14 -0700 (PDT)
>> 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
(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.
Rename it to a numeral one greater than the max numeric frame name.
Rename any other frames to numerals also."
(setq frame (or frame (selected-frame))
frames (or frames (list frame)))
(let ((onum (frame-number frame))
(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))
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."
(dolist (fr (frame-list))
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)