From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: FW: commands to select things of different kinds Date: Sun, 9 Mar 2008 08:45:18 -0800 Message-ID: <001c01c88204$f5891160$0600a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_001D_01C881C1.E765D160" X-Trace: ger.gmane.org 1205081458 29191 80.91.229.12 (9 Mar 2008 16:50:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Mar 2008 16:50:58 +0000 (UTC) To: "Emacs-Devel" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 09 17:51:25 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 1JYOk6-0004bE-HI for ged-emacs-devel@m.gmane.org; Sun, 09 Mar 2008 17:51:23 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JYOjY-0008Bi-8J for ged-emacs-devel@m.gmane.org; Sun, 09 Mar 2008 12:50:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JYOez-0005Iq-ER for emacs-devel@gnu.org; Sun, 09 Mar 2008 12:46:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JYOex-0005IA-Rk for emacs-devel@gnu.org; Sun, 09 Mar 2008 12:46:05 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JYOex-0005I2-GS for emacs-devel@gnu.org; Sun, 09 Mar 2008 12:46:03 -0400 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JYOew-0005Bu-UE for emacs-devel@gnu.org; Sun, 09 Mar 2008 12:46:03 -0400 Original-Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id m29Gk0Kv017368 for ; Sun, 9 Mar 2008 11:46:00 -0500 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with ESMTP id m29FnPRE012856 for ; Sun, 9 Mar 2008 10:45:59 -0600 Original-Received: from inet-141-146-46-1.oracle.com by acsmt351.oracle.com with ESMTP id 3605741651205081146; Sun, 09 Mar 2008 09:45:46 -0700 Original-Received: from dradamslap1 (/141.144.112.116) by bhmail.oracle.com (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 09 Mar 2008 09:45:45 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcfI93C8LHk/FVeGQviUZ4fvpTb04yjiNEtgBWEgxjA= X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:91897 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_001D_01C881C1.E765D160 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Resending, at Richard's request. > -----Original Message----- > From: Richard Stallman Sent: Wednesday, July 18, 2007 1:54 PM > To: Drew Adams > > Not really; haven't thought much about it. As I said, > I've been using > `C-M-SPC' for `mark-thing' (stealing from `mark-sexp') > and `M-@' for > `cycle-thing-region' (stealing from `mark-word'). > > Those might be a good replacement, because I would expect people don't > use those two bindings very much. But we have to ask people first. > -----Original Message----- > From: Drew Adams Sent: Tuesday, July 17, 2007 9:52 PM > To: rms@gnu.org > > > > If the region is not yet active, then you are prompted (with > > > completion) for the type of thing to select. The default type > > > is `sexp'. > > > > For the first such thing, the region is not active, so you > > are prompted. For subsequent (successive) things, there is > > no prompt - the same type is used as the last. When you are > > prompted, `sexp' is the default type. > > > > I see. Maybe it is a good idea. If people like it, we can > install it > > in Emacs. > > > > Do you have suggested bindings for these two commands? > > Not really; haven't thought much about it. As I said, I've > been using `C-M-SPC' for `mark-thing' (stealing from > `mark-sexp') and `M-@' for `cycle-thing-region' (stealing > from `mark-word'). But, as I also said, I'm not suggesting > changing those bindings for Emacs. > > I think these commands are mainly useful for Transient Mark > mode, if that helps. Perhaps there are some bindings that > normally make less sense in t-m mode, which could therefore > be recuperated. I don't know. > -----Original Message----- > From: Drew Adams Sent: Monday, July 16, 2007 12:17 AM > To: Emacs-Devel > > Any interest in these commands? They let you select (that is, > mark) various > things at or near point. They are most useful in Transient > Mark mode - they > act differently depending on whether the mark is active. > > * `mark-thing' selects successive things, starting at point. > The mark is put > at the same place that command 'forward-'thing would put it > (using the same > prefix argument). If the region is not yet active, then you > are prompted > (with completion) for the type of thing to select. The default type is > `sexp'. > > * `cycle-thing-region' selects one thing at or near point > (just the thing, > not from point through the thing, even if the thing is not exactly at > point). Repeat it to cycle among the thing types - one thing > of the current > type is selected at each invocation. The default order of > types is `word', > `sexp', `list', `line', `sentence', `paragraph', `page', > `defun', `number', > `form'. That order is customizable, and a major mode could > also change it to > put the most commonly used types first. > > I bind `mark-thing' to `C-M-SPC' as a replacement for `mark-sexp'. > > I bind `cycle-thing-region' to `M-@' as a replacement for > `mark-word'. (By > default, it does what `mark-word' does without a prefix arg. Unlike, > `mark-thing', however, `cycle-thing-region' does not accept a > prefix arg.) > > I don't propose these bindings for Emacs generally, but if you use > transient-mark mode you might want to give them a try. > > To select successive things in transient-mark mode, you can use > `cycle-thing-region' as an alternative to completion for > choosing the thing > type for `mark-thing' - but you need to use `C-x C-x' between > the two. That > is, you can use 'M-@ C-x C-x C-M-SPC' to select successive > words, 'M-@ M-@ > C-x C-x C-M-SPC' for successive symbols, and so on. > > The code is attached. ------=_NextPart_000_001D_01C881C1.E765D160 Content-Type: application/octet-stream; name="thing-cmds.el" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="thing-cmds.el" ;;; thing-cmds.el --- Commands that use things, as defined by = `thingatpt.el'.=0A= ;; =0A= ;; Filename: thing-cmds.el=0A= ;; Description: Commands that use things, as defined by `thingatpt.el'.=0A= ;; Author: Drew Adams=0A= ;; Maintainer: Drew Adams=0A= ;; Copyright (C) 2006-2007, Drew Adams, all rights reserved.=0A= ;; Created: Sun Jul 30 16:40:29 2006=0A= ;; Version: 20.1=0A= ;; Last-Updated: Sun Jul 15 23:58:11 2007 (-25200 Pacific Daylight Time)=0A= ;; By: dradams=0A= ;; Update #: 41=0A= ;; URL: http://www.emacswiki.org/cgi-bin/wiki/thing-cmds.el=0A= ;; Keywords: thingatpt, thing, region, selection=0A= ;; Compatibility: GNU Emacs 20.x, GNU Emacs 21.x, GNU Emacs 22.x=0A= ;; =0A= ;; Features that might be required by this library:=0A= ;;=0A= ;; `thingatpt', `thingatpt+'.=0A= ;;=0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;; =0A= ;;; Commentary:=0A= ;;=0A= ;; You can use the commands defined here to select different kinds of=0A= ;; text entities ("things"). They are especially useful in=0A= ;; combination with Transient Mark mode.=0A= ;; =0A= ;; Commands defined here:=0A= ;;=0A= ;; `cycle-thing-region', `mark-thing', `select-thing-near-point',=0A= ;; `thing-region'.=0A= ;;=0A= ;; User options defined here:=0A= ;;=0A= ;; `thing-types'.=0A= ;;=0A= ;; Internal variables defined here:=0A= ;;=0A= ;; `mark-thing-type', `thing-region-index'.=0A= ;;=0A= ;; Put this in your init file (`~/.emacs'): (require 'thing-cmds)=0A= ;;=0A= ;; Suggested key bindings (these will replace the standard bindings=0A= ;; for `mark-sexp' and `mark-word'):=0A= ;;=0A= ;; (global-set-key [(control meta ? )] 'mark-thing) ; vs `mark-sexp'=0A= ;; (global-set-key [(meta ?@)] 'cycle-thing-region) ; vs `mark-word'=0A= ;;=0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;; =0A= ;;; Change log:=0A= ;;=0A= ;; 2007/07/15 dadams=0A= ;; Added cycle-thing-region-point.=0A= ;; cycle-thing-region: Save point in cycle-thing-region-point and = reuse it.=0A= ;; 2006/07/30 dadams=0A= ;; Created.=0A= ;; =0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;; =0A= ;; This program is free software; you can redistribute it and/or=0A= ;; modify it under the terms of the GNU General Public License as=0A= ;; published by the Free Software Foundation; either version 2, or=0A= ;; (at your option) any later version.=0A= ;; =0A= ;; This program is distributed in the hope that it will be useful,=0A= ;; but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU=0A= ;; General Public License for more details.=0A= ;; =0A= ;; You should have received a copy of the GNU General Public License=0A= ;; along with this program; see the file COPYING. If not, write to=0A= ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth=0A= ;; Floor, Boston, MA 02110-1301, USA.=0A= ;; =0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;; =0A= ;;; Code:=0A= =0A= (require 'thingatpt+ nil t) ;; (no error if not found): = bounds-of-thing-at-point=0A= (require 'thingatpt) ;; bounds-of-thing-at-point=0A= =0A= (when (< emacs-major-version 20) (eval-when-compile (require 'cl))) ;; = when, unless=0A= =0A= ;;;;;;;;;;;;;;;;;;;;;;;;=0A= =0A= (defun thing-region (thing)=0A= "Set the region around a THING near the cursor.=0A= You are prompted for the type of thing. Completion is available for=0A= some standard types of thing, but you can enter any type.=0A= The cursor is placed at the end of the region. You can return it to=0A= the original location by using `C-u C-SPC' twice."=0A= (interactive (list (let ((icicle-sort-function nil))=0A= (completing-read "Type of thing: " (mapcar #'list = thing-types)=0A= nil nil nil nil "sexp"))))=0A= (let* ((bds (if (fboundp 'bounds-of-thing-nearest-point) ; In = `thingatpt+.el'.=0A= (bounds-of-thing-nearest-point (intern thing))=0A= (bounds-of-thing-at-point (intern thing))))=0A= (start (car bds))=0A= (end (cdr bds)))=0A= (cond ((and start end)=0A= (push-mark (point) t) ; Mark position, so can use `C-u = C-SPC'.=0A= (goto-char end)=0A= (push-mark start t 'activate)=0A= (setq deactivate-mark nil)=0A= thing) ; Return thing.=0A= (t=0A= (message "No `%s' near point" thing)=0A= (setq deactivate-mark nil)=0A= nil)))) ; Return nil: no thing found.=0A= =0A= (defalias 'select-thing-near-point 'cycle-thing-region)=0A= (defun cycle-thing-region ()=0A= "Select a thing near point. Successive uses select different things.=0A= In Transient Mark mode, you can follow this with `\\[mark-thing]' to = select=0A= successive things of the same type, but to do that you must first use=0A= `C-x C-x': `\\[cycle-thing-region] C-x C-x \\[mark-thing]'"=0A= (interactive)=0A= (if (eq last-command this-command)=0A= (goto-char cycle-thing-region-point)=0A= (setq thing-region-index 0)=0A= (setq cycle-thing-region-point (point)))=0A= (let* ((thing (elt thing-types thing-region-index))=0A= (success (thing-region thing)))=0A= (setq thing-region-index (1+ thing-region-index))=0A= (when success=0A= (setq mark-thing-type (intern thing)) ; Save it for `mark-thing'.=0A= (message "%s" (capitalize (elt thing-types (1- = thing-region-index)))))=0A= (when (>=3D thing-region-index (length thing-types)) (setq = thing-region-index 0))))=0A= =0A= (defcustom thing-types '("word" "symbol" "sexp" "list" "line" "sentence"=0A= "paragraph" "page" "defun" "number" "form")=0A= "List of thing types. Used for completion and `cycle-thing-region'.=0A= Each element is a string that names a type of text entity for which=0A= there is a either a corresponding `forward-'thing operation, or=0A= corresponding `beginning-of-'thing and `end-of-'thing operations.=0A= Examples include \"word\", \"sentence\", and \"defun\"."=0A= :type '(repeat string))=0A= =0A= (defvar thing-region-index 0 "Index of current thing in `thing-types'.")=0A= =0A= (defvar mark-thing-type nil "Current thing type used by `mark-thing'.")=0A= =0A= (defvar cycle-thing-region-point nil=0A= "Position of point before `cycle-thing-region'.")=0A= =0A= (defun mark-thing (thing &optional arg allow-extend)=0A= "Set the mark ARG THINGs from point.=0A= THING is a string that names a type of thing: \"word\", \"sexp\", and=0A= so on. See option `thing-types' for more examples.=0A= =0A= The mark is put at the same place command `forward-'THING would put it=0A= with the same prefix argument.=0A= =0A= If the prefix argument (ARG) is negative, then point is put at the end=0A= of the THING, amd mark is put at the beginning of the THING or a=0A= previous THING.=0A= =0A= Interactively:=0A= =0A= You are prompted for THING. Completion is available for the types of=0A= thing in `thing-types', but you can enter any type.=0A= =0A= If `mark-thing' is repeated or if the mark is active (in Transient=0A= Mark mode), then it marks the next ARG THINGs, after the ones already=0A= marked."=0A= (interactive "i\nP\np") ; THING arg is nil (ignored) = interactively.=0A= (cond ((and allow-extend (or (and (eq last-command this-command) (mark = t))=0A= (and transient-mark-mode mark-active)))=0A= (setq arg (if arg=0A= (prefix-numeric-value arg)=0A= (if (< (mark) (point)) -1 1)))=0A= (set-mark (save-excursion=0A= (goto-char (mark))=0A= (forward-thing mark-thing-type arg)=0A= (point))))=0A= (t=0A= (setq mark-thing-type=0A= (or thing (intern (let ((icicle-sort-function nil))=0A= (completing-read "Type of thing: "=0A= (mapcar #'list = thing-types)=0A= nil nil nil nil = "sexp")))))=0A= (push-mark (save-excursion=0A= (forward-thing mark-thing-type = (prefix-numeric-value arg))=0A= (point))=0A= nil t)))=0A= (setq deactivate-mark nil))=0A= =0A= ;;;;;;;;;;;;;;;;;;;;;;;;=0A= =0A= (provide 'thing-cmds)=0A= =0A= ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;=0A= ;;; thing-cmds.el ends here=0A= ------=_NextPart_000_001D_01C881C1.E765D160--