From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Miles Bader Newsgroups: gmane.emacs.devel Subject: deactivation in "shift-select" mode Date: Sat, 08 Mar 2008 10:24:37 +0900 Message-ID: <871w6mc8iy.fsf_-_@catnip.gol.com> References: <200803050637.m256bXL3008361@sallyv1.ics.uci.edu> <87hcfkdhqk.fsf@stupidchicken.com> <87d4q8sq9c.fsf@jurta.org> <8763w0n393.fsf@catnip.gol.com> <871w6ounk0.fsf@kfs-lx.rd.rdm> <87ablacdxt.fsf@catnip.gol.com> Reply-To: Miles Bader NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1204939515 3565 80.91.229.12 (8 Mar 2008 01:25:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 8 Mar 2008 01:25:15 +0000 (UTC) Cc: juri@jurta.org, cyd@stupidchicken.com, "Kim F. Storm" , emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 08 02:25:41 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JXnoa-0007WN-LL for ged-emacs-devel@m.gmane.org; Sat, 08 Mar 2008 02:25:32 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JXno2-0007L6-Ce for ged-emacs-devel@m.gmane.org; Fri, 07 Mar 2008 20:24:58 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JXnny-0007Jg-8S for emacs-devel@gnu.org; Fri, 07 Mar 2008 20:24:54 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JXnnv-0007JT-RE for emacs-devel@gnu.org; Fri, 07 Mar 2008 20:24:52 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JXnnv-0007JQ-Lx for emacs-devel@gnu.org; Fri, 07 Mar 2008 20:24:51 -0500 Original-Received: from smtp12.dentaku.gol.com ([203.216.5.74]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JXnno-0001eT-Ad; Fri, 07 Mar 2008 20:24:44 -0500 Original-Received: from 203-216-96-086.dsl.gol.ne.jp ([203.216.96.86] helo=catnip.gol.com) by smtp12.dentaku.gol.com with esmtpa (Dentaku) id 1JXnnj-0004RF-WD; Sat, 08 Mar 2008 10:24:40 +0900 Original-Received: by catnip.gol.com (Postfix, from userid 1000) id A618D2FF7; Sat, 8 Mar 2008 10:24:38 +0900 (JST) System-Type: i686-pc-linux-gnu In-Reply-To: <87ablacdxt.fsf@catnip.gol.com> (Miles Bader's message of "Sat, 08 Mar 2008 08:27:42 +0900") Original-Lines: 36 X-Virus-Scanned: ClamAV GOL (outbound) X-Abuse-Complaints: abuse@gol.com X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:91684 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Johan Bockg=C3=A5rd pointed out (on the #emacs irc channel) that transient-mark-mode actually _already_ has enough functionality to allow implementing the desired "deactivation" behavior for shift-select (where non-shifted movement keys automatically deactivate any mark which was activated by shifted movement keys), without using post-command-hook at all! Basically his idea is to use the "only mode" feature of transient-mark-mode (setting the transient-mark-mode variable to 'only instead of t). I've attached a proof-of-concept that shows how it works; this code only implements shift-select for the basic cursor movement keys plus forward/backward-word, but it's obviously trivial to extend to any other commands desired. This implementation only works if transient-mark-mode is disabled, because of the way the transient-mark-mode "only mode" works; my guess is that this restriction would probably be pretty easy to remove by simply having a separate variable to enable "only mode" instead of overloading the meaning of the basic transient-mark-mode variable. Anyway, here's the example code, which is very simple and seems to work quite nicely; check it! -Miles --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=shift-mark.el Content-Transfer-Encoding: quoted-printable Content-Description: proof-of-concept for \"shift-select\" without post-command-hook ;; Proof-of-concept for "shift-mark" commands without using ;; post-command-hook. The idea is from Johan Bockg=C3=A5rd. ;; ;; Currently only works when transient-mark-mode is disabled. ;; ;; If there were was generalized "shift" binding, the individual ;; "*-mark" functions wouldn't be needed. (defun shift-mark () (unless (region-active-p) (push-mark-command nil t)) (when (or (not transient-mark-mode) (eq 'identity transient-mark-mode)) (setq transient-mark-mode 'only))) (defun forward-char-mark (&optional n) (interactive "p") (shift-mark) (forward-char n)) (defun backward-char-mark (&optional n) (interactive "p") (shift-mark) (backward-char n)) (defun forward-word-mark (&optional n) (interactive "p") (shift-mark) (forward-word n)) (defun backward-word-mark (&optional n) (interactive "p") (shift-mark) (backward-word n)) (defun next-line-mark (&optional n) (interactive "p") (shift-mark) (next-line n)) (defun previous-line-mark (&optional n) (interactive "p") (shift-mark) (previous-line n)) (global-set-key [(shift right)] 'forward-char-mark) (global-set-key [(shift control ?f)] 'forward-char-mark) (global-set-key [(shift left)] 'backward-char-mark) (global-set-key [(shift control ?b)] 'backward-char-mark) (global-set-key [(shift meta f)] 'forward-word-mark) (global-set-key [(shift control right)] 'forward-word-mark) (global-set-key [(shift meta b)] 'backward-word-mark) (global-set-key [(shift control left)] 'backward-word-mark) (global-set-key [(shift control n)] 'next-line-mark) (global-set-key [(shift down)] 'next-line-mark) (global-set-key [(shift control p)] 'previous-line-mark) (global-set-key [(shift up)] 'previous-line-mark) --=-=-= -- Genealogy, n. An account of one's descent from an ancestor who did not particularly care to trace his own. --=-=-=--