Documentation

Registered by Andreas Roehler

Delivers a set of functions to return, mover over or
 manipulate a given THING. THING may be a well known
 form as word, paragraph, but also a char class as
 `alnum' or a new defined thing.

For example `ar-alnum-atpt' will return all
 alpha-numerical chars below and around cursor as a
 string. `ar-bounds-of-alnum-atpt' returns the
 borders of that string as a list and so on.

Here some settings:

(global-set-key [(super \()] 'ar-parentize-region-atpt)
 (global-set-key [(super \/)] 'ar-slash-region-atpt)
 (global-set-key [(super \<)] 'ar-lesser-angle-region-atpt)
 (global-set-key [(super \>)] 'ar-greater-angle-region-atpt)
 (global-set-key [(super \[)] 'ar-bracket-region-atpt)
 (global-set-key [(super \\)] 'ar-backslash-region-atpt)
 (global-set-key [(super \{)] 'ar-brace-region-atpt)

Beside of <super>, the key already tells what to pick.
 Quite often used are commands like this:

(global-set-key [(control c)(\")] 'ar-doublequote-or-copy-atpt)
 (global-set-key [(control c)(\')] 'ar-singlequote-or-copy-atpt)

Presently for a given THING the following is
 implemented:

ar-THING-atpt
 ar-THING-bounds-atpt
 ar-THING-beginning-position-atpt
 ar-THING-end-position-atpt
 ar-THING-beginning-atpt
 ar-THING-end-atpt
 ar-THING-length-atpt
 ar-THING-copy-atpt
 ar-THING-kill-atpt
 ar-THING-forward-atpt
 ar-THING-backward-atpt
 ar-THING-transpose-atpt
 ar-THING-sort-atpt
 ar-THING-check-atpt

Beside of the mentioned above, esists still a couple of
 functions, whose use is much less probable:

ar-THING-slash-atpt
 ar-THING-double-backslash-atpt
 ar-THING-doubleslash-atpt
 ar-THING-delete-in-region
 ar-blok-THING-atpt
 ar-THING-escape-atpt
 ar-THING-doublequote-atpt
 ar-THING-doubleslash-paren-atpt
 ar-THING-slashparen-atpt
 ar-THING-dollar-atpt
 ar-THING-equalize-atpt
 ar-THING-greater-angle-atpt
 ar-THING-lesser-angle-atpt
 ar-THING-backslash-atpt
 ar-THING-brace-atpt
 ar-THING-bracket-atpt
 ar-comment-THING-atpt
 ar-commatize-THING-atpt
 ar-quote-THING-atpt
 ar-THING-hyphen-atpt
 ar-THING-mark-atpt
 ar-THING-hide-atpt
 ar-THING-show-atpt
 ar-THING-hide-show-atpt
 ar-THING-left-right-singlequote-atpt
 ar-THING-parentize-atpt
 ar-THING-separate-atpt
 ar-THING-singlequote-atpt
 ar-THING-trim-atpt
 ar-THING-left-trim-atpt
 ar-THING-right-trim-atpt
 ar-underscore-THING-atpt
 ar-whitespace-THING-atpt

To see what's implemented, consult contents of
 variables at the end of thingatpt-utils-base.el as
 `ar-atpt-delimlist', `ar-atpt-delimited-list', etc.

Call one of the test-functions `C-u ar-th-delimtest'
 with come chars in scratch-buffer
 or any else changable buffer to get an impression.

The idea comes from Mike Williams
 <email address hidden>, author of
 thingatpt.el

The goal is to have a set of similar forms. For
 example, to provide a word with double-quotes around
 it, call ar-doublequote-word-atpt. In a similar way you
 may double-quote not just a word, but any object
 instrumented here as THING. To make parentheses
 around it call ar-parentize-word-atpt, etc.

Move-functions of this package differ from common
 behaviour in such, as `ar-forward-word-atpt' stops
 not after THING, but on the last char of
 THING. That's in order to enable a call of
 thing-at-point functions at the end
 position. Otherwise, when cursor stops after word
 (THING) as does `forward-word', `ar-word-atpt' would return
 nil.

To see other features, maybe try `ar-separate-list-atpt'
 or `ar-comment-list-atpt' while point is inside a
 list. Try it again with an abstract char-class as
 [:alnum:], i.e. try `ar-comment-alnum-atpt',
 `ar-brace-alnum-atpt' etc.

This utility comes with test-functions which return
 the possible results of most functions (exception
 are the kill-fns). Call th-test, th-mv-test
 or th-delimtest over text. That-delimtest
 changes but restores the buffer. Customize the speed
 of execution via `ar-th-test-delay'

Diffs to basics of required thingatpt.el:
 `bounds-of-thing-at-point' is replaced by a new
 `ar-th-bounds', which now first searches
 backward. As a consequence several
 `beginning-op-at' and `end-op-at' constructs had
 to be rewritten.

Behavior in general is not validating; i.e. if you
 call ar-url-atpt and there is no url, all chars at
 point may be picked, which could be part of a
 url. Sometimes, however, a kind of validation may be
 introduced.

If calling from a program `bounds-of-THING-atpt' is
 recommended as an entry-point. It delivers a list
 with beg and end positions.

In case of trouble, please send me a bug report. Any
 ideas and comments welcome.

You might be interested also to visit Drew Adam's
http://www.emacswiki.org/emacs/thingatpt+.el
 which predates this approach and was helpful writing it.

Thing-at-point delivers a portion of the
 buffer. Thats useful, if THING is not as easy to grasp as a word.
 For example the first string of an objekt like:

("4[[:punct:] \t\r\n]? [[:punct:] \t\r\n]?C[[:punct:] \t\r\n]?.[[:punct:] \t\r\n]?2[[:punct:] \t\r\n]?4[[:punct:] \t\r\n]?6[[:punct:] \t\r\n]?4[[:punct:] \t\r\n]?/[[:punct:] \t\r\n]?0[[:punct:] \t\r\n]?3[[:punct:] \t\r\n]? [[:punct:] \t\r\n]?B" . "blah blub B")

Remove comments and put the cursor somewhere into the first
 string:
 `ar-doublequoted-atpt' will return it, copied into the kill-ring,
 enabling yanking it and a lot of further actions.
 So far THING is simply picked up.

Different approach combines copying, deleting with delimiting

if region is active:

(global-set-key [(control c) (\")] 'ar-doublequote-or-copy-atpt)

will provide doublequotes at beginning and end of region.

With negative argument it deletes the doublequoted portion under
 point.

Without any argument these functions return as their simplier
 counterparts

With universal argument [(control u)] delimiters --i.e. doublequotes, slashes, whatever-- are stripped.

THING as a buffer substring is determined by
 move-functions specified for thingatpt, called
 beginning-op-at and end-op-at. Point is stored
 after move, beginning and end delivered as pair: as
 consed bounds-of-thing. It's easy to write your own
 thing-at-point functions that way. You need the
 caller and both move forms:

(defun MY-FORM-atpt (&optional arg)
   " "
   (interactive "p")
   (ar-th 'MY-FORM arg))

(put 'MY-FORM 'beginning-op-at
            (lambda () MY-FORWARD-MOVE-CODE))

(put 'MY-FORM 'end-op-at
      (lambda () MY-BACKWARD-MOVE-CODE))

For example if you want to pick all chars at point
 which are written between a string "AAA" and a
 "BBB", which may exist as
 AAA Luckily detected a lot of things! BBB
 After evaluation of
 (put 'MY-FORM 'beginning-op-at
      (lambda ()
        (search-backward "AAA" nil 'move 1)
        ;; step chars of search expression back
        (forward-char 3)))

(put 'MY-FORM 'end-op-at
      (lambda ()
        (search-forward "BBB" nil 'move 1)
        (forward-char -3)))
 together with the functions definition above, it's ready.
 M-x MY-FORM-atpt
 (while point inside) you should see:
 " Luckily detected a lot of things! "
 in the minibuffer.
(?)

Blueprint information

Status:
Complete
Approver:
Andreas Roehler
Priority:
Medium
Drafter:
Andreas Roehler
Direction:
Approved
Assignee:
Andreas Roehler
Definition:
Approved
Series goal:
Accepted for trunk
Implementation:
Informational Informational
Milestone target:
milestone icon 1.5
Started by
Andreas Roehler
Completed by
Andreas Roehler

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.