unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Subject: M-a casts anchored `sentence-end' adrift.
Date: Mon, 7 Jul 2008 09:01:35 +0000	[thread overview]
Message-ID: <20080707090135.GA1901@muc.de> (raw)

Hi, Emacs!

Suppose you've got an enhanced text mode, in which lines and paragraphs
look something like this:

  o - This is a paragraph with a "bullet" heading.  Typically, it
    extends over several lines, with indentation.
    o - This line starts a "sub-bullet" paragraph.

Now put point on the word "heading" and do M-a.  This is going to move
point to the "bullet".  Clearly, the Right Thing is to move point to "This".

An obvious way to do this is to enhance `sentence-end' so that " o - "
gets recognised as a full stop.  Something like this should do it:

(defvar my-sentence-end
  (let (sentence-end)
    (concat "^[ \t]*o - [ \t]+\\|\\("
            (sentence-end)
	    "\\)")))

, then put
  (setq sentence-end my-sentence-end) 
in the mode startup code.  Note the "^" at the start of the regexp.

However, M-a _still_ doesn't work.  The problem is that (forward-sentence
-1) limits its re-search-backwards to the paragraph TEXT, as opposed to
the entire paragraph including leading whitespace.

The specification of sentence-end doesn't preclude anchoring a
"full-stop" at BOL (or even EOL).  Therefore, there is a bug.  The
following patch fixes it.

Can anybody see any problems with this patch?  May I install it?



2008-07-07  Alan Mackenzie  <acm@muc.de>

	* textmodes/paragraphs.el (forward-sentence): Change limit of
	re-search-backward to allow values of `sentence-end' anchored at
	BOL.


*** paragraphs.el	2008-05-29 18:20:14.000000000 +0000
--- paragraphs.070708.el	2008-07-07 08:54:43.856911952 +0000
***************
*** 887,893 ****
          (sentence-end (sentence-end)))
      (while (< arg 0)
        (let ((pos (point))
! 	    (par-beg (save-excursion (start-of-paragraph-text) (point))))
         (if (and (re-search-backward sentence-end par-beg t)
  		(or (< (match-end 0) pos)
  		    (re-search-backward sentence-end par-beg t)))
--- 887,893 ----
          (sentence-end (sentence-end)))
      (while (< arg 0)
        (let ((pos (point))
! 	    (par-beg (save-excursion (backward-paragraph) (point))))
         (if (and (re-search-backward sentence-end par-beg t)
  		(or (< (match-end 0) pos)
  		    (re-search-backward sentence-end par-beg t)))


-- 
Alan Mackenzie (Nuremberg, Germany).




             reply	other threads:[~2008-07-07  9:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-07  9:01 Alan Mackenzie [this message]
2009-01-12  4:25 ` M-a casts anchored `sentence-end' adrift Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080707090135.GA1901@muc.de \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).