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: commands to select things of different kinds Date: Mon, 16 Jul 2007 00:16:59 -0700 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0003_01C7C73E.A045B090" X-Trace: sea.gmane.org 1184570252 27588 80.91.229.12 (16 Jul 2007 07:17:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2007 07:17:32 +0000 (UTC) To: "Emacs-Devel" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 16 09:17:31 2007 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 1IAKpm-0005JX-8P for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2007 09:17:30 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IAKpl-00076R-GY for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2007 03:17:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IAKph-000763-19 for emacs-devel@gnu.org; Mon, 16 Jul 2007 03:17:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IAKpe-000755-8n for emacs-devel@gnu.org; Mon, 16 Jul 2007 03:17:24 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IAKpe-000752-1i for emacs-devel@gnu.org; Mon, 16 Jul 2007 03:17:22 -0400 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IAKpd-0000lI-GG for emacs-devel@gnu.org; Mon, 16 Jul 2007 03:17:21 -0400 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id l6G7HJaK016797 for ; Mon, 16 Jul 2007 01:17:20 -0600 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id l6G7HJ4u012299 for ; Mon, 16 Jul 2007 01:17:19 -0600 Original-Received: from dhcp-amer-csvpn-gw2-141-144-73-5.vpn.oracle.com by acsmt350.oracle.com with ESMTP id 3041739871184570234; Mon, 16 Jul 2007 00:17:14 -0700 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: 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:74880 Archived-At: This is a multi-part message in MIME format. ------=_NextPart_000_0003_01C7C73E.A045B090 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by rgminet01.oracle.com id l6G7HJaK016797 Any interest in these commands? They let you select (that is, mark) vario= us things at or near point. They are most useful in Transient Mark mode - th= ey 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 =91forward-=92thing would put it (using th= e 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 curre= nt 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'. (B= y 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 thi= ng type for `mark-thing' - but you need to use `C-x C-x' between the two. Th= at is, you can use =91M-@ C-x C-x C-M-SPC=92 to select successive words, =91= M-@ M-@ C-x C-x C-M-SPC=92 for successive symbols, and so on. The code is attached. ------=_NextPart_000_0003_01C7C73E.A045B090 Content-Type: application/octet-stream; name="thing-cmds.el" Content-Disposition: attachment; filename="thing-cmds.el" Content-Transfer-Encoding: quoted-printable ;;; 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_0003_01C7C73E.A045B090 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ------=_NextPart_000_0003_01C7C73E.A045B090--