From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Vitalie Spinu Newsgroups: gmane.emacs.devel Subject: [PATCH] set-temporary-overlay-map improvement and make windresize exit on other commands Date: Sun, 09 Jun 2013 14:07:16 +0200 Organization: EUR Message-ID: <87mwqzo5cb.fsf_-_@gmail.com> References: <87txlts7so.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1370779650 2498 80.91.229.3 (9 Jun 2013 12:07:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Jun 2013 12:07:30 +0000 (UTC) Cc: Stefan Monnier , Gauthier =?utf-8?Q?=C3=96s?= =?utf-8?Q?tervall?= , emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 09 14:07:30 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UlePB-0001gn-Ia for ged-emacs-devel@m.gmane.org; Sun, 09 Jun 2013 14:07:29 +0200 Original-Received: from localhost ([::1]:58726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlePB-0001r9-2q for ged-emacs-devel@m.gmane.org; Sun, 09 Jun 2013 08:07:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UleP5-0001qv-H1 for emacs-devel@gnu.org; Sun, 09 Jun 2013 08:07:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UleP2-00077r-9L for emacs-devel@gnu.org; Sun, 09 Jun 2013 08:07:23 -0400 Original-Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]:61589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UleP1-00077F-WE for emacs-devel@gnu.org; Sun, 09 Jun 2013 08:07:20 -0400 Original-Received: by mail-wg0-f54.google.com with SMTP id j13so4147725wgh.33 for ; Sun, 09 Jun 2013 05:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:organization:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=7sItQiCpCKGmbfg4gBeLr6DLPSyfK6KR3UHnPfAxrN4=; b=INakg69tr63RUcgVtPDYA1e4eeFmWmho3W0GsUoI0ymSUe76kvMUZvyY2xIrRtXe5m FLy0IEMogaPVPhA/b5OXLzXion8Gb5sQr88b6mZamqE+9bHW/ISh8Ksws7TKDrzyuGvZ 24t0QBZG+iSHxoJ0gx0g9rQy3QD1ImspSrTd6DyRcqzdMhMYBoCFQHF80fHMLxQBgn0z pKrRRXiMJibkUYeRbBbWt3jIYrXYK0ozJhapBkvKg4/2fZgwtATY+q46k/4oq6+c1flU CsSJ++7tlrsIzz9dhSv2ifHmibm6saIcoQkns3hluo6coneZyhLo8tMP5qINuxSmFwRq DADQ== X-Received: by 10.180.185.225 with SMTP id ff1mr2524073wic.36.1370779639363; Sun, 09 Jun 2013 05:07:19 -0700 (PDT) Original-Received: from localhost (dhcp-077-249-018-128.chello.nl. [77.249.18.128]) by mx.google.com with ESMTPSA id dz8sm1410629wib.11.2013.06.09.05.07.17 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 09 Jun 2013 05:07:17 -0700 (PDT) In-Reply-To: <87txlts7so.fsf@mail.jurta.org> (Juri Linkov's message of "Fri, 24 May 2013 01:04:40 +0300") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::236 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160282 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-add-ON-EXIT-argument-to-set-temporary-overlay-map.patch >From 103046272cb842451c57c6bf097755b2ef40f474 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=patch-windresize-exit-on-other-command.patch *** /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 --=-=-= Content-Type: text/plain >> Juri Linkov >> 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) --=-=-=--