emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] set-temporary-overlay-map improvement and make windresize exit o


From: Vitalie Spinu
Subject: [PATCH] set-temporary-overlay-map improvement and make windresize exit on other commands
Date: Sun, 09 Jun 2013 14:07:16 +0200
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux)

Here are two simple patches that make windresize work with
set-temporary-overlay-map. 

First patch is to emacs trunk and adds ON-EXIT argument to
set-temporary-overlay-map. Irrespective of windresize I think this is a
useful addition anyhow. It opens the way for set-temporary-overlay-map
to be directly used by electric commands that need to clean up temporary
buffers, messages, window configuration etc.

Second patch is to windresize. Depending on the value of
windresize-exit-on-other-command, windresize will exit on any other
command than those defined in windresize-map. I set it to t by
default. It seems like a nicer default given the discussion on current
thread.

My .emacs now has 
  
   (define-key ctl-x-map "w" 'windresize)

    Vitalie

>From 103046272cb842451c57c6bf097755b2ef40f474 Mon Sep 17 00:00:00 2001
From: Vitalie Spinu <address@hidden>
Date: Sun, 9 Jun 2013 13:38:23 +0200
Subject: [PATCH] add ON-EXIT argument to set-temporary-overlay-map

* lisp/subr.el (set-temporary-overlay-map): Optional ON-EXIT argument is
  a function that is called after the deactivation of MAP.
---
 lisp/subr.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 65943ae..bb35a9a 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4260,7 +4260,7 @@ If NUM is non-nil, return non-nil iff F can be called 
with NUM args."
       (and (>= num (car res))
           (or (eq 'many (cdr res)) (<= num (cdr res)))))))
 
-(defun set-temporary-overlay-map (map &optional keep-pred)
+(defun set-temporary-overlay-map (map &optional keep-pred on-exit)
   "Set MAP as a temporary keymap taking precedence over most other keymaps.
 Note that this does NOT take precedence over the \"overriding\" maps
 `overriding-terminal-local-map' and `overriding-local-map' (or the
@@ -4270,7 +4270,10 @@ found in MAP, the normal key lookup sequence then 
continues.
 Normally, MAP is used only once.  If the optional argument
 KEEP-PRED is t, MAP stays active if a key from MAP is used.
 KEEP-PRED can also be a function of no arguments: if it returns
-non-nil then MAP stays active."
+non-nil then MAP stays active.
+
+Optional ON-EXIT argument is a function that is called after the
+deactivation of MAP."
   (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map"))
          (overlaysym (make-symbol "t"))
          (alist (list (cons overlaysym map)))
@@ -4286,7 +4289,9 @@ non-nil then MAP stays active."
                (set ',overlaysym nil)   ;Just in case.
                (remove-hook 'pre-command-hook ',clearfunsym)
                (setq emulation-mode-map-alists
-                     (delq ',alist emulation-mode-map-alists))))))
+                     (delq ',alist emulation-mode-map-alists))
+               ,(when on-exit
+                  `(funcall ',on-exit))))))
     (set overlaysym overlaysym)
     (fset clearfunsym clearfun)
     (add-hook 'pre-command-hook clearfunsym)
-- 
1.8.1.2

*** /home/vitoshka/Dropbox/ELPA/windresize-0.1/windresize.el.~1~        
2013-06-09 12:01:27.257902916 +0200
--- /home/vitoshka/Dropbox/ELPA/windresize-0.1/windresize.el    2013-06-09 
13:46:50.737784424 +0200
***************
*** 109,114 ****
--- 109,120 ----
    :group 'convenience
    :type 'integer)
  
+ (defcustom windresize-exit-on-other-command t
+   "If non-nil, windresize will exit on any command not defined in
+ `windresize-map'"
+   :group 'convenience
+   :type 'boolean)
+ 
  (defcustom windresize-modifiers '((meta shift) meta
                                  (control meta) control)
    "A list of modifiers for arrow keys commands.
***************
*** 157,164 ****
  (defvar windresize-map
    (let ((map (make-sparse-keymap)))
      (define-key map [remap self-insert-command] 'windresize-other-char)
-     (define-key map (kbd "M-x") 'windresize-other-char)
-     (define-key map (kbd "C-h") 'windresize-other-char)
      ;; move borders outwards or shrink/enlarge
      (define-key map [left] 'windresize-left)
      (define-key map [right] 'windresize-right)
--- 163,168 ----
***************
*** 364,371 ****
                 (current-window-configuration))
      (setq windresize-buffer (current-buffer))
      ;; set overriding map and pre/post-command hooks
!     (setq overriding-terminal-local-map windresize-map)
!     (setq overriding-local-map-menu-flag t)
      (windresize-add-command-hooks)
      ;; set the initial message
      (setq windresize-msg
--- 368,379 ----
                 (current-window-configuration))
      (setq windresize-buffer (current-buffer))
      ;; set overriding map and pre/post-command hooks
!     (if windresize-exit-on-other-command
!         (set-temporary-overlay-map windresize-map t 'windresize-exit)
!       (define-key windresize-map (kbd "M-x") 'windresize-other-char)
!       (define-key windresize-map (kbd "C-h") 'windresize-other-char)
!       (setq overriding-terminal-local-map windresize-map)
!       (setq overriding-local-map-menu-flag t))
      (windresize-add-command-hooks)
      ;; set the initial message
      (setq windresize-msg


 >> Juri Linkov <address@hidden>
 >> on Fri, 24 May 2013 01:04:40 +0300 wrote:

 >>> I will give it a try, but I feel that functionality should be
 >>> built-in.
 >> 
 >> Yes clearly, that is needed before we can consider it to make C-x
 >> [{}^] redundant.

 JL> If the goal is to replace `C-x [{}^]' with one global keybinding,
 JL> the currently free and intuitive key prefix for window related commands
 JL> would be `C-x w', so that a command to activate window-resizing
 JL> key sequence could be bound to `C-x w r'.

 JL> Until this is implemented, something like below could help
 JL> for experimenting with possible implementations:

 JL> (defvar window-resize-keymap
 JL>   (let ((map (make-sparse-keymap)))
 JL>     ;; Standard keys:
 JL>     (define-key map "0" 'delete-window)
 JL>     (define-key map "1" 'delete-other-windows)
 JL>     (define-key map "2" 'split-window-below)
 JL>     (define-key map "3" 'split-window-right)
 JL>     (define-key map "o" 'other-window)
 JL>     (define-key map "^" 'enlarge-window)
 JL>     (define-key map "}" 'enlarge-window-horizontally)
 JL>     (define-key map "{" 'shrink-window-horizontally)
 JL>     (define-key map "-" 'shrink-window-if-larger-than-buffer)
 JL>     (define-key map "+" 'balance-windows)
 JL>     ;; Additional keys:
 JL>     (define-key map "v"     'shrink-window)
 JL>     (define-key map [down]  'shrink-window)
 JL>     (define-key map [up]    'enlarge-window)
 JL>     (define-key map [left]  'shrink-window-horizontally)
 JL>     (define-key map [right] 'enlarge-window-horizontally)
 JL>     map)
 JL>   "Keymap to resize windows.")

 JL> (advice-add 'enlarge-window-horizontally :after (lambda (delta)
 JL>             (set-temporary-overlay-map window-resize-keymap)))
 JL> (advice-add 'shrink-window-horizontally :after (lambda (delta)
 JL>             (set-temporary-overlay-map window-resize-keymap)))
 JL> (advice-add 'enlarge-window :after (lambda (delta &optional horizontal)
 JL>             (set-temporary-overlay-map window-resize-keymap)))
 JL> (advice-add 'shrink-window :after (lambda (delta &optional horizontal)
 JL>             (set-temporary-overlay-map window-resize-keymap)))

 JL> (defun window-resize-init ()
 JL>   (interactive)
 JL>   (message "Use window-resizing keys...")
 JL>   (set-temporary-overlay-map window-resize-keymap))

 JL> (define-key ctl-x-map "wr" 'window-resize-init)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]