Giter Site home page Giter Site logo

switch-window's Introduction

目录

  1. What is switch-window
    1. Installation
    2. Configure and Usage
    3. Tips
      1. I want to select a window with "a-z" instead of "1-9".
      2. I want to let window to show bigger label.
      3. I want to hide window label when window's number < 3
      4. I want to select minibuffer with label "z".
      5. I want to auto resize a window when switch to it
      6. Switch-window seem to conflict with Exwm, how to do?
      7. I use text terminal, but I want bigger label.
      8. I want to use image or icon as label.
      9. `switch-window-shortcut-appearance' can't satisfy my need. how to do?
      10. Have any other similar package exist?
    4. Changelog
      1. 1.6.0 - 2018-06-06
      2. 1.5.0 - 2017-04-29
      3. 1.0.0 - 2015-01-14
      4. 0.11 - 2013-09-14
      5. 0.10 - 2011-06-19
      6. 0.9 - 2010-11-11 - emacs22 called, it wants some support
      7. 0.8 - 2010-09-13 - 999
      8. 0.7 - 2010-08-23 - window-dedicated-p
      9. 0.6 - 2010-08-12 - Minibuf-1
      10. 0.5 - 2010-08-08 - Polishing

What is switch-window

switch-window is an Emacs window switch tool, which offer a visual way to choose a window to switch to, delete, split or other operations.

img

Installation

  1. Config melpa source, please read: http://melpa.org/#/getting-started
  2. M-x package-install RET switch-window RET

Note: User can install switch-window with El-Get too.

Configure and Usage

(require 'switch-window)
(global-set-key (kbd "C-x o") 'switch-window)
(global-set-key (kbd "C-x 1") 'switch-window-then-maximize)
(global-set-key (kbd "C-x 2") 'switch-window-then-split-below)
(global-set-key (kbd "C-x 3") 'switch-window-then-split-right)
(global-set-key (kbd "C-x 0") 'switch-window-then-delete)

(global-set-key (kbd "C-x 4 d") 'switch-window-then-dired)
(global-set-key (kbd "C-x 4 f") 'switch-window-then-find-file)
(global-set-key (kbd "C-x 4 m") 'switch-window-then-compose-mail)
(global-set-key (kbd "C-x 4 r") 'switch-window-then-find-file-read-only)

(global-set-key (kbd "C-x 4 C-f") 'switch-window-then-find-file)
(global-set-key (kbd "C-x 4 C-o") 'switch-window-then-display-buffer)

(global-set-key (kbd "C-x 4 0") 'switch-window-then-kill-buffer)

When switch-window is enabled, user can use the below five keys:

key command description
"i" Move the border up
"k" Move the border down
"j" Move the border left
"l" Move the border right
"b" Balance windows
"SPC" Resume auto-resize

If you want to customize this feature, please see variable: `switch-window-extra-map'.

Note: if you use auto-resize window feature, you must know that when you execute above window operate commands, auto-resize feature will be disabled temporarily, you should use above "SPC" key to resume.

Tips

I want to select a window with "a-z" instead of "1-9".

(setq switch-window-shortcut-style 'qwerty)

Note: user can arrange qwerty shortcuts by variable `switch-window-qwerty-shortcuts'.

I want to let window to show bigger label.

The face of label is switch-window-label, user can change it :height with custiomize-face

I want to hide window label when window's number < 3

(setq switch-window-threshold 2)

I want to select minibuffer with label "z".

(setq switch-window-minibuffer-shortcut ?z)

I want to auto resize a window when switch to it

(setq switch-window-auto-resize-window t)
(setq switch-window-default-window-size 0.8) ;80% of frame size
(switch-window-mouse-mode) ;auto resize when switch window with mouse

Advanced usage:

(setq switch-window-auto-resize-window
      (lambda ()
        (equal (buffer-name) "*scratch*"))) ;when return t, run auto switch
(setq switch-window-default-window-size '(0.8 . 0.6)) ;80% width and 60% height of frame

By the way, you can use package golden-ratio also.

Switch-window seem to conflict with Exwm, how to do?

By default, switch-window get user's input with the help of function `read-event', this approach does not work well with Exwm (Emacs X window manager), user should set the below variable and use minibuffer to get input instead:

(setq switch-window-input-style 'minibuffer)

Note: if you use minibuffer to get input, the feature about `switch-window-minibuffer-shortcut' will not work well.

I use text terminal, but I want bigger label.

The only choice is using asciiart, which draw a bigger label with small ascii char.

(setq switch-window-shortcut-appearance 'asciiart)

img

I want to use image or icon as label.

  1. Prepare your label images, rename them to: 1.png … 9.png, a.png … z.png.

    You can use other image types supported by Emacs, please see: `image-types'.

  2. Put all above images to directory: `switch-window-image-directory'.

  3. Set variable: `switch-window-shortcut-appearance'

    (setq switch-window-shortcut-appearance 'image)
    

img

`switch-window-shortcut-appearance' can't satisfy my need. how to do?

All you should do is hacking you own label buffer function, for example: my-switch-window-label-buffer-function, and set the below variable:

(setq switch-window-label-buffer-function
      'my-switch-window-label-buffer-function)

Have any other similar package exist?

Changelog

1.6.0 - 2018-06-06

  1. Add switch-window-label face to control the appearance of label.
  2. Remove `switch-window-increase', use switch-window-label face instead.
  3. Show orig text with label: see `switch-window-background'
  4. Switch between frames: see `switch-window-multiple-frames'
  5. [incompatible] `switch-window-label-buffer-function''s arguments have changed, user should update when use it.

1.5.0 - 2017-04-29

  • Implement commands:
    1. switch-window-then-maximize
    2. switch-window-then-delete
    3. switch-window-then-split-below
    4. switch-window-then-split-right
    5. switch-window-then-split-horizontally
    6. switch-window-then-split-vertically
    7. switch-window-then-swap-buffer
  • Let switch-window work well with Exwm (Emacs X window manager).
  • User can customize switch-window label's appearance.

1.0.0 - 2015-01-14

  • Please fixme.

0.11 - 2013-09-14

  • restore point to end-of-buffer for windows where it was the case after switching, fixing an anoying bug.

0.10 - 2011-06-19

  • implement M-x delete-other-window (thanks developernotes on github)

0.9 - 2010-11-11 - emacs22 called, it wants some support

  • implement a propertize based hack to support emacs22

0.8 - 2010-09-13 - 999

  • Suport more than 9 windows (with a single key to type)
  • Use quail-keyboard-layout to choose single key labels for windows

0.7 - 2010-08-23 - window-dedicated-p

  • temporarily unset the window dedicated flag for displaying the numbers, patch from René Kyllingstad [email protected]
  • fix timeout and RET handling wrt to not changing window selection

0.6 - 2010-08-12 - Minibuf-1

  • add support for selecting the minibuffer when it's active
  • some try at a better horizontal centering
  • assorted cleanup

0.5 - 2010-08-08 - Polishing

  • dim:switch-window-increase is now a maximum value

Converted from switch-window.el by el2org .

switch-window's People

Contributors

akirak avatar artemkovalyov avatar developernotes avatar dimitri avatar endgame avatar gempesaw avatar gzz2000 avatar havner avatar iri-e avatar lamdor avatar mehw avatar monkeyjunglejuice avatar purcell avatar ramnes avatar redjocker avatar samhasler avatar seagle0128 avatar sgarciac avatar sjrmanning avatar swsnr avatar titanofold avatar tumashu avatar wdkrnls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

switch-window's Issues

window stops updating after switching windows

Say you have 3 windows. Window 1 is an eshell, 2 is an text file, and 3 is an output file. If I perform a task that causes window 1 to continuously scroll, such as code compilation, and I switch focus to window 3 during that time (C-x o 3), window 1 will stop scrolling.

This is problematic because the only way to determine if compilation has finished is to switch back to window 1 and jump to the bottom of the buffer.

Problem with find file other window

Hi:

When using switch-window-then-find-file there is a problem as a replacement for find-file-other-window.

The problem is that if there are 2 windows with two files from different directories; then the default path for switch-window-then-find-file is the path of the file in the "other window"; not in the current one. This is opposed to find-file-other-window where the path is the directory of the current and not the new/future one.

using switch-window across multiple frames

Is it possible ?

From the source it seems that hacking:

(defun switch-window-list (&optional from-current-window)
  "list windows for current frame, starting at top left unless
from-current-window is not nil"
  (if (or from-current-window switch-window-relative)
      (window-list nil nil)
    (window-list nil nil (frame-first-window))))

would do the job, am I right?

Thx!

Key configuration

How do I configure custom keys for switching windows? E.g. I want to use u i a e o.

Support "other-window" functions (ones that start C-x 4)

C-x 4 C-h lists the following commands in my emacs:

C-x 4 C-f       find-file-other-window
C-x 4 C-o       display-buffer
C-x 4 .         xref-find-definitions-other-window
C-x 4 0         kill-buffer-and-window
C-x 4 a         add-change-log-entry-other-window
C-x 4 b         switch-to-buffer-other-window
C-x 4 c         clone-indirect-buffer-other-window
C-x 4 d         dired-other-window
C-x 4 f         find-file-other-window
C-x 4 m         compose-mail-other-window
C-x 4 r         find-file-read-only-other-window

It would be neat to write a wrapper that lets you select the "other window", then do one of these things. Looks like several applications of switch-window--then. I may try to put together a PR for this.

error when changing window with 5 windows asciiart and querty

I was having problems with this line

(nth (cl-position
                            label
                            (remove "" (split-string "123456789abcdefjhijklmnopqrstuvwxyz" ""))
                            :test #'equal)
                           switch-window-asciiart))

of this function

(defun switch-window--create-label-buffer (&optional _window buffer label background)
  "The default LABEL BUFFER create funcion."
  (with-current-buffer buffer
    (setq truncate-lines t)
    (when switch-window-background
      (insert background)
      (goto-char (point-min)))
    (cond
     ((eq switch-window-shortcut-appearance 'asciiart)
      (setq line-spacing nil)
      (let* ((lines (split-string
                     (replace-regexp-in-string
                      "^\n" ""
                      (nth (cl-position
                            label
                            (remove "" (split-string "123456789abcdefjhijklmnopqrstuvwxyz" ""))
                            :test #'equal)
                           switch-window-asciiart))
                     "\n"))
             (num (apply #'max (mapcar #'length lines))))
        ;; Deal with "let: End of buffer" problem.
        ;; Maybe not beautiful, but simple :-)
        (goto-char (point-max))
        (dotimes (_ 20)
          (insert (make-string num ? ))
          (insert "\n"))
        (goto-char (point-min))
        (dolist (line lines)
          (delete-char num)
          (insert (format (concat "%-" (number-to-string num) "s") line))
          (insert "  ")
          (forward-line 1))))
     ((eq switch-window-shortcut-appearance 'text)
      (insert (propertize label 'face 'switch-window-label)))
     ((eq switch-window-shortcut-appearance 'image)
      (let ((types (cl-copy-seq image-types))
            file)
        (while types
          (let* ((type (pop types))
                 (file1 (format "%s%s.%S"
                                (file-name-as-directory switch-window-image-directory)
                                label type)))
            (when (file-exists-p file1)
              (setq file file1)
              (setq types nil))))
        (if (and file (display-images-p))
            (insert-image-file (expand-file-name file))
          (insert (propertize label 'face 'switch-window-label))))))
    (insert " ")
    (goto-char (point-min))
    (setq-local buffer-read-only t)
    (setq-local show-trailing-whitespace nil)
    buffer))

At first the of label was ";" so cl-position was evaluting to nil since there is no ";" on the string.
Then I removed ";" from switch-window-qwerty-shortcuts.
Now label was "g" and also there is no "g" on the string, there are 2 "j" and 0 "g". cl-position was evaluating to nil again and throwing error.
Then I removed "g" from switch-window-qwerty-shortcuts and that fixed changing windows.

It is easy to deduce it is a typo on the "j" located where should be "g".
The ";" is also not present on switch-window-asciiart.el, so I'm not sure it should be present on switch-window-qwerty-shortcuts default values

An error occurred when there were more than 8 windows

Hello, and sorry for my poor English.

When the window is more than 8, press C - x o cannot start switch-window.
And has the following error information:

switch-window--create-label-buffer: Wrong type argument: stringp, nil

Complete error message (set debug-on-error to t) :

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  propertize(nil face switch-window-label)
  switch-window--create-label-buffer(#<window 20 on *Messages*> #<buffer  *nil: *Messages**> nil #("Loading /home/yuki/.emacs.d/custom.el (source)...done\nWrote /home/yuki/.emacs.d/.emacs.desktop.lock\nDesktop: 1 frame, 5 buffers restored.\nLoading /home/yuki/.emacs.d/recentf...done\nCleaning up the recentf list...done (0 removed)\nInit completed in 1.690s\nFor information about GNU Emacs and the GNU system, type C-h C-a.\nYou should have a section marked \";;; Code:\" [2 times]\n<C-mouse-1> is undefined\n" 0 181 (face switch-window-background) 228 400 (face switch-window-background)))
  switch-window--display-number(#<window 20 on *Messages*> 9)
  switch-window--prompt("Move to window: ")
  switch-window--then("Move to window: " switch-window--other-window-or-frame)
  switch-window()
  funcall-interactively(switch-window)
  call-interactively(switch-window nil nil)
  command-execute(switch-window)

My config:

(setq switch-window-shortcut-style 'qwerty)
(setq switch-window-qwerty-shortcuts
      '("a" "s" "d" "f" "j" "k" "l" ";" "w" "e" "i" "o"))

(global-set-key (kbd "C-x o") 'switch-window)

Thank you.

Necessary to Display Window Number When There Are Only 2 Windows?

switch-window-threshold's default sorta takes care of this but, if a window's frame count passes then returns to the threshold, window numbers will still be displayed on C-x o.

Based on this variables description this behavior makes sense, as it just activates it, but there should be a counter that is refreshed when a frame's windows are modified, preventing one from unnecessarily having to choose a window when the choice is obvious.

Window numbers are incorrect in daemon mode

Hi,

When I using emacsclient -a "" -nw to start Emacs as daemon, the window numbers are incorrect while switching window. It happens on GNU Emacs 26.1/27.0.50 with Ubuntu/Mint Linux/macOS.

Only two windows, but the numbers are 2 and 3 in the screenshot below.
image

BTW, the numbers are correct in ace-window and winum.

Switching without the "hint"

Hi,

love the switch-window package.

I was wondering if it is possible to implement a function that can be bound to a key that doesn't show the number-hints in the buffers. If you have a relatively fixed setup, you know the numbers by heart quickly - and then not having the buffers flash in and out would be nice.

One idea would be:

when typing C-x o, it first does nothing, but waits for a number. When you type 0 - it shows the hint and continues waiting for a number.

Thanks!

"end of buffer" in emacs 27.1

system: ubuntu 20.04
emacs 27.1

switch-window seems to only able to create two windows. when trying to create more windows, it shows End of buffer:

switch-window--create-label-buffer: End of buffer [2 times]

It probably has something to do with creating the overlaying labels?

Switch Window Kill

It would be a great feature if you could use switch-window but to kill a window instead of switching to it. Maybe it justifies making a new package called something like kill-window.

Bug in alphabet shortcut style

screen shot 2017-09-24 at 19 27 44

Seems some windows are not activated, and the if condition doesn't match in such situation. Then `w in (switch-window--list)` will also be skipped, while it should't be.
(defun switch-window--enumerate ()
  "Return a list of one-letter strings to label current windows"
  (cl-loop for w in (switch-window--list)
           for x in (switch-window--list-keys)
           collect (if (and switch-window-minibuffer-shortcut
                            (minibuffer-window-active-p w))
                       (char-to-string switch-window-minibuffer-shortcut)
                     x)))

It should be something like this:

int index = 0;
for x in switch-window--list-keys {
  if condition statement {
    collect.add(switch-window--list[index]);
    i++;
  }
}

I'm not familiar with elisp, so I don't know how to fix it.

wish: show buffer contents while displaying numbers

switch-window is really great. This is a feature request: For me it would be even better if I could see the contents of the windwos after hitting C-x o. Is it possible to overlay the windows contents with the numbers shown in order to switch to a window?

Can't switch out of minibuffer

I can't switch out of the minibuffer. I get the following error.

[Command attempted to use minibuffer while in minibuffer]

I noticed this while using consult-ripgrep. It has a preview feature which is handy for moving back and forth between search results and files I want to edit. Without switch-window, it works fine. Am I supposed to enable recursive minibuffers?

switch-window-multiple-frames returns error in EXWM

I am using switch-window in Emacs 27.1 under EXWM with two frames, spanning two monitors.
My configuration is as follows:

(use-package switch-window
  :ensure t
  :defer t
  :config
  (setq switch-window-multiple-frames nil)
  (setq switch-window-input-style 'minibuffer)
  (setq switch-window-increase 4)
  (setq switch-window-threshold 2)
  (setq switch-window-shortcut-style 'qwerty)
  (setq switch-window-qwerty-shortcuts
	'("j" "k" "l" "a" "s" "d" "f")) ; ö does not work without pressing RET
  :bind
  ([remap other-window] . switch-window))

If I change the first config line into

  (setq switch-window-multiple-frames t)

and subsequently call C-x o (switch-window), (using the debug-on-error variable) the first monitor's frame populates with labels as it should
image
No labels appear on the second monitor, pressing the key associated to a label does nothing (because the debugger is trapping input, I guess).

The stack trace looks as follows:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  propertize(nil face switch-window-label)
  (insert (propertize label 'face 'switch-window-label))
  (cond ((eq switch-window-shortcut-appearance 'asciiart) (setq line-spacing nil) (insert (replace-regexp-in-string "^\n" "" (nth (cl-position label (remove "" (split-string "123456789abcdefjhijklmnopqrstuvwxyz" "")) :test #'equal) switch-window-asciiart)))) ((eq switch-window-shortcut-appearance 'text) (insert (propertize label 'face 'switch-window-label))) ((eq switch-window-shortcut-appearance 'image) (let ((types (cl-copy-seq image-types)) file) (while types (let* ((type (car-safe ...)) (file1 (format "%s%s.%S" ... label type))) (if (file-exists-p file1) (progn (setq file file1) (setq types nil))))) (if (and file (display-images-p)) (insert-image-file (expand-file-name file)) (insert (propertize label 'face 'switch-window-label))))))
  (save-current-buffer (set-buffer buffer) (if switch-window-background (progn (insert background) (goto-char (point-min)))) (cond ((eq switch-window-shortcut-appearance 'asciiart) (setq line-spacing nil) (insert (replace-regexp-in-string "^\n" "" (nth (cl-position label (remove "" ...) :test #'equal) switch-window-asciiart)))) ((eq switch-window-shortcut-appearance 'text) (insert (propertize label 'face 'switch-window-label))) ((eq switch-window-shortcut-appearance 'image) (let ((types (cl-copy-seq image-types)) file) (while types (let* ((type ...) (file1 ...)) (if (file-exists-p file1) (progn ... ...)))) (if (and file (display-images-p)) (insert-image-file (expand-file-name file)) (insert (propertize label 'face 'switch-window-label)))))) (insert " ") (goto-char (point-min)) (set (make-local-variable 'buffer-read-only) t) (set (make-local-variable 'show-trailing-whitespace) nil) buffer)
  switch-window--create-label-buffer(#<window 15 on *scratch*> #<buffer  *nil: *scratch**> nil "")
  switch-window--display-number(#<window 15 on *scratch*> 5)
  switch-window--prompt("Move to window: ")
  switch-window--then("Move to window: " switch-window--other-window-or-frame)
  switch-window()
  funcall-interactively(switch-window)
  call-interactively(switch-window nil nil)
  command-execute(switch-window)

Use letters to choose buffer

Hi,

Is there a way to use letters rather than numbers to choose buffers?
I think if there's an option for that it will be very good.

Thanks,

Alpha Ho

Customize label face?

switch-window is stable and fast. I switched from ace-window.

Actually this is a new feature request to customize the label face like ace-window. Different color or size will make it more fancy.

Moreover, it's better provide the customization to keep the background display, which is similar as aw-background of ace-window.

use to switch buffers in windows

Say I have three windows open:

a | b | c

and I'd like to have the left most buffer in the middle window, and the middle buffer in the left most window:

b | a | c

Does this sound like a feasible thing that I could write a switch window function to do? I'd be in window a, invoke switch-window-switch-contents or whatever, choose the middle window, and it would exchange the buffer-window contents. Or maybe even already implemented? If you think it's feasible I'll take a crack at it! :)

Use popup in ascii mode

Hi:

Very thanks for implementing this. I really like the package but it is a shame that the buffer's content is hidden in ascii mode; it feels unnatural.

Could you consider to use popups or anything else that doesn't hides the whole window content, but just the region where the ascii-art letter appears in terminal?

Thanks in advance,
Ergus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.