unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* FW: commands to select things of different kinds
@ 2008-04-18 22:06 Drew Adams
  2008-04-19  3:42 ` Stefan Monnier
  0 siblings, 1 reply; 88+ messages in thread
From: Drew Adams @ 2008-04-18 22:06 UTC (permalink / raw)
  To: Emacs-Devel

[-- Attachment #1: Type: text/plain, Size: 3736 bytes --]

Resending -

----
Sent: Sunday, March 09, 2008 9:45 AM
Resending, at Richard's request. 

> 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.



[-- Attachment #2: thing-cmds.el --]
[-- Type: application/octet-stream, Size: 8042 bytes --]

;;; thing-cmds.el --- Commands that use things, as defined by `thingatpt.el'.
;; 
;; Filename: thing-cmds.el
;; Description: Commands that use things, as defined by `thingatpt.el'.
;; Author: Drew Adams
;; Maintainer: Drew Adams
;; Copyright (C) 2006-2007, Drew Adams, all rights reserved.
;; Created: Sun Jul 30 16:40:29 2006
;; Version: 20.1
;; Last-Updated: Sun Jul 15 23:58:11 2007 (-25200 Pacific Daylight Time)
;;           By: dradams
;;     Update #: 41
;; URL: http://www.emacswiki.org/cgi-bin/wiki/thing-cmds.el
;; Keywords: thingatpt, thing, region, selection
;; Compatibility: GNU Emacs 20.x, GNU Emacs 21.x, GNU Emacs 22.x
;; 
;; Features that might be required by this library:
;;
;;   `thingatpt', `thingatpt+'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Commentary:
;;
;;  You can use the commands defined here to select different kinds of
;;  text entities ("things").  They are especially useful in
;;  combination with Transient Mark mode.
;; 
;;  Commands defined here:
;;
;;    `cycle-thing-region', `mark-thing', `select-thing-near-point',
;;    `thing-region'.
;;
;;  User options defined here:
;;
;;    `thing-types'.
;;
;;  Internal variables defined here:
;;
;;    `mark-thing-type', `thing-region-index'.
;;
;;  Put this in your init file (`~/.emacs'): (require 'thing-cmds)
;;
;;  Suggested key bindings (these will replace the standard bindings
;;  for `mark-sexp' and `mark-word'):
;;
;;  (global-set-key [(control meta ? )] 'mark-thing) ; vs `mark-sexp'
;;  (global-set-key [(meta ?@)] 'cycle-thing-region) ; vs `mark-word'
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Change log:
;;
;; 2007/07/15 dadams
;;     Added cycle-thing-region-point.
;;     cycle-thing-region: Save point in cycle-thing-region-point and reuse it.
;; 2006/07/30 dadams
;;     Created.
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;; 
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;; 
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;;; Code:

(require 'thingatpt+ nil t) ;; (no error if not found): bounds-of-thing-at-point
(require 'thingatpt) ;; bounds-of-thing-at-point

(when (< emacs-major-version 20) (eval-when-compile (require 'cl))) ;; when, unless

;;;;;;;;;;;;;;;;;;;;;;;;

(defun thing-region (thing)
  "Set the region around a THING near the cursor.
You are prompted for the type of thing.  Completion is available for
some standard types of thing, but you can enter any type.
The cursor is placed at the end of the region.  You can return it to
the original location by using `C-u C-SPC' twice."
  (interactive (list (let ((icicle-sort-function nil))
                       (completing-read "Type of thing: " (mapcar #'list thing-types)
                                        nil nil nil nil "sexp"))))
  (let* ((bds (if (fboundp 'bounds-of-thing-nearest-point) ; In `thingatpt+.el'.
                  (bounds-of-thing-nearest-point (intern thing))
                (bounds-of-thing-at-point (intern thing))))
         (start (car bds))
         (end (cdr bds)))
    (cond ((and start end)
           (push-mark (point) t)        ; Mark position, so can use `C-u C-SPC'.
           (goto-char end)
           (push-mark start t 'activate)
           (setq deactivate-mark nil)
           thing)                       ; Return thing.
          (t
           (message "No `%s' near point" thing)
           (setq deactivate-mark nil)
           nil))))                      ; Return nil: no thing found.

(defalias 'select-thing-near-point 'cycle-thing-region)
(defun cycle-thing-region ()
  "Select a thing near point.  Successive uses select different things.
In Transient Mark mode, you can follow this with `\\[mark-thing]' to select
successive things of the same type, but to do that you must first use
`C-x C-x': `\\[cycle-thing-region] C-x C-x \\[mark-thing]'"
  (interactive)
  (if (eq last-command this-command)
      (goto-char cycle-thing-region-point)
    (setq thing-region-index 0)
    (setq cycle-thing-region-point (point)))
  (let* ((thing (elt thing-types thing-region-index))
         (success (thing-region thing)))
    (setq thing-region-index (1+ thing-region-index))
    (when success
      (setq mark-thing-type (intern thing)) ; Save it for `mark-thing'.
      (message "%s" (capitalize (elt thing-types (1- thing-region-index)))))
    (when (>= thing-region-index (length thing-types)) (setq thing-region-index 0))))

(defcustom thing-types '("word" "symbol" "sexp" "list" "line" "sentence"
                         "paragraph" "page" "defun" "number" "form")
  "List of thing types.  Used for completion and `cycle-thing-region'.
Each element is a string that names a type of text entity for which
there is a either a corresponding `forward-'thing operation, or
corresponding `beginning-of-'thing and `end-of-'thing operations.
Examples include \"word\", \"sentence\", and \"defun\"."
  :type '(repeat string))

(defvar thing-region-index 0 "Index of current thing in `thing-types'.")

(defvar mark-thing-type nil "Current thing type used by `mark-thing'.")

(defvar cycle-thing-region-point nil
  "Position of point before `cycle-thing-region'.")

(defun mark-thing (thing &optional arg allow-extend)
  "Set the mark ARG THINGs from point.
THING is a string that names a type of thing: \"word\", \"sexp\", and
so on.  See option `thing-types' for more examples.

The mark is put at the same place command `forward-'THING would put it
with the same prefix argument.

If the prefix argument (ARG) is negative, then point is put at the end
of the THING, amd mark is put at the beginning of the THING or a
previous THING.

Interactively:

You are prompted for THING.  Completion is available for the types of
thing in `thing-types', but you can enter any type.

If `mark-thing' is repeated or if the mark is active (in Transient
Mark mode), then it marks the next ARG THINGs, after the ones already
marked."
  (interactive "i\nP\np")               ; THING arg is nil (ignored) interactively.
  (cond ((and allow-extend (or (and (eq last-command this-command) (mark t))
                               (and transient-mark-mode mark-active)))
	 (setq arg (if arg
                       (prefix-numeric-value arg)
		     (if (< (mark) (point)) -1 1)))
	 (set-mark (save-excursion
                     (goto-char (mark))
                     (forward-thing mark-thing-type arg)
                     (point))))
	(t
         (setq mark-thing-type
               (or thing (intern (let ((icicle-sort-function nil))
                                   (completing-read "Type of thing: "
                                                    (mapcar #'list thing-types)
                                                    nil nil nil nil "sexp")))))
	 (push-mark (save-excursion
                      (forward-thing mark-thing-type (prefix-numeric-value arg))
                      (point))
                    nil t)))
  (setq deactivate-mark nil))

;;;;;;;;;;;;;;;;;;;;;;;;

(provide 'thing-cmds)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; thing-cmds.el ends here

^ permalink raw reply	[flat|nested] 88+ messages in thread

end of thread, other threads:[~2008-04-22 20:08 UTC | newest]

Thread overview: 88+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-18 22:06 FW: commands to select things of different kinds Drew Adams
2008-04-19  3:42 ` Stefan Monnier
2008-04-19 20:11   ` Juri Linkov
2008-04-19 20:22     ` David Kastrup
2008-04-19 20:33       ` delete-selection-mode (was: FW: commands to select things of different kinds) Juri Linkov
2008-04-20 13:47         ` delete-selection-mode David Kastrup
2008-04-19 23:18       ` FW: commands to select things of different kinds Richard Stallman
2008-04-19 23:43         ` delete-selection-mode (was: FW: commands to select things of different kinds) Juri Linkov
2008-04-20 10:10           ` Kim F. Storm
2008-04-20 14:57           ` delete-selection-mode Eli Zaretskii
2008-04-21  3:08             ` delete-selection-mode Richard Stallman
2008-04-21  3:59               ` delete-selection-mode Thomas Lord
2008-04-21 19:47                 ` delete-selection-mode Richard Stallman
2008-04-21 20:57                 ` delete-selection-mode Alan Mackenzie
2008-04-21 21:40                   ` delete-selection-mode Lennart Borgman (gmail)
2008-04-20 18:34           ` delete-selection-mode Chong Yidong
2008-04-20 19:25             ` delete-selection-mode Stefan Monnier
2008-04-20 19:31               ` delete-selection-mode Dan Nicolaescu
2008-04-20 19:48                 ` delete-selection-mode David Kastrup
2008-04-20 20:28                   ` delete-selection-mode Lennart Borgman (gmail)
2008-04-20 20:32                     ` delete-selection-mode David Kastrup
2008-04-20 20:53                       ` delete-selection-mode Lennart Borgman (gmail)
2008-04-20 21:20                         ` delete-selection-mode David Kastrup
2008-04-20 21:42                           ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21  5:37                             ` delete-selection-mode David Kastrup
2008-04-21  6:18                               ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21  6:24                                 ` delete-selection-mode David Kastrup
2008-04-21  6:40                                   ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21  9:36                                     ` delete-selection-mode David Kastrup
2008-04-21 16:44                                       ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21 17:47                                         ` delete-selection-mode Stefan Monnier
2008-04-21 18:12                                           ` delete-selection-mode David Kastrup
2008-04-21 19:53                                             ` delete-selection-mode Jason Rumney
2008-04-21 20:02                                               ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21 20:28                                                 ` delete-selection-mode David Kastrup
2008-04-21  6:44                                 ` delete-selection-mode Drew Adams
2008-04-21 14:19                                 ` delete-selection-mode Stefan Monnier
2008-04-21 16:41                                   ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21 17:01                                     ` delete-selection-mode David Kastrup
2008-04-21 17:45                                       ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21 17:58                                         ` delete-selection-mode Alfred M. Szmidt
2008-04-21 18:36                                           ` delete-selection-mode Paul R
2008-04-21 18:51                                             ` delete-selection-mode David Kastrup
2008-04-21 19:04                                               ` delete-selection-mode Juanma Barranquero
2008-04-21 19:48                                                 ` delete-selection-mode David Kastrup
2008-04-21 20:06                                                   ` delete-selection-mode Juanma Barranquero
2008-04-21 20:09                                                     ` delete-selection-mode David Kastrup
2008-04-21 20:10                                                       ` delete-selection-mode Juanma Barranquero
2008-04-21 19:54                                               ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21 19:56                                               ` delete-selection-mode Jason Rumney
2008-04-21 20:07                                                 ` delete-selection-mode David Kastrup
2008-04-22  4:20                                                 ` delete-selection-mode Richard Stallman
2008-04-22  5:34                                                   ` delete-selection-mode Thomas Lord
2008-04-22  8:10                                                   ` delete-selection-mode Jason Rumney
2008-04-22  8:38                                                     ` delete-selection-mode David Kastrup
2008-04-22 20:08                                                       ` delete-selection-mode Richard Stallman
2008-04-22 20:08                                                     ` delete-selection-mode Richard Stallman
2008-04-21 20:03                                               ` delete-selection-mode Paul R
2008-04-21 20:39                                                 ` delete-selection-mode David Kastrup
2008-04-21 19:51                                             ` delete-selection-mode Alfred M. Szmidt
2008-04-21 20:06                                               ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21 19:10                                     ` delete-selection-mode Robert J. Chassell
2008-04-21 19:47                                       ` delete-selection-mode Lennart Borgman (gmail)
2008-04-22 12:20                                         ` delete-selection-mode Robert J. Chassell
2008-04-22 12:34                                           ` delete-selection-mode David Kastrup
2008-04-22 15:54                                             ` delete-selection-mode Robert J. Chassell
2008-04-22 13:29                                           ` delete-selection-mode David Reitter
2008-04-21 19:47                                 ` delete-selection-mode Richard Stallman
2008-04-20 21:06                   ` delete-selection-mode Drew Adams
2008-04-20 21:27                     ` delete-selection-mode Eli Zaretskii
2008-04-20 22:28                       ` delete-selection-mode Drew Adams
2008-04-20 19:32               ` delete-selection-mode David Kastrup
2008-04-20 19:37           ` delete-selection-mode (was: FW: commands to select things of different kinds) Alan Mackenzie
2008-04-20 19:29             ` delete-selection-mode David Kastrup
2008-04-20 21:26               ` delete-selection-mode Jason Rumney
2008-04-20 21:45                 ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21  0:10                   ` delete-selection-mode Drew Adams
2008-04-21  0:23                     ` delete-selection-mode Lennart Borgman (gmail)
2008-04-21  1:44                       ` delete-selection-mode Drew Adams
2008-04-21  0:28                     ` delete-selection-mode Jason Rumney
2008-04-21  1:44                       ` delete-selection-mode Drew Adams
2008-04-21  3:07           ` delete-selection-mode (was: FW: commands to select things of different kinds) Richard Stallman
2008-04-19 20:35     ` FW: commands to select things of different kinds Drew Adams
2008-04-19 22:54       ` Juri Linkov
2008-04-19 23:22         ` Drew Adams
2008-04-20 23:52           ` Juri Linkov
2008-04-21  0:13             ` Drew Adams
2008-04-21  1:03             ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).