help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's a better regexp for 'sentence-end' variable??


From: Oliver Scholz
Subject: Re: What's a better regexp for 'sentence-end' variable??
Date: Fri, 21 Feb 2003 19:53:40 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-msvc-nt5.1.2600)

gebser@ameritech.net writes:
[...]
> Oliver Scholz at 12:35 (UTC+0100) on Thu, 20 Feb 2003 said:
[...]
> = It is in general a bad idea to modify the Elisp sources, because it is
> = absolutely unnessary, but may lead to trouble. The place to change
> = anything on the Lisp level is your .emacs. 
[...]

> You're right.  But it's the hacker in me that likes to just go in and
> change things... 

I just wanted to be sure that you know what you are doing. :-)

[It could lead to problems, btw, when doing remote debugging on
usenet, because your Emacs would behave differently from what other
people would expect ... *eg* O.k., o.k., I won't mention it again ... ]

[...]
>
> ;;Doesn't work. 1
> (define-key html-mode-map (kbd "M-e") 'my-html-forward-sentence)
>
> ;;Doesn't work.  2    
> (define-key sgml-mode-map (kbd "M-e") 'my-html-forward-sentence)
>
> ;; Doesn't work. 3
> ;(eval-after-load 'sgml-mode
> ;  (define-key sgml-mode-map (kbd "M-e") 'my-html-forward-sentence))
    ^^^

[I think, that should be ...'(define-key ... (Note the quote.)]

> ;;Doesn't work. 4
> ;(add-hook 'sgml-mode-hook
> ;(lambda () (local-set-key (kbd "M-e") 'my-html-forward-sentence)))
> ...

Hmm. Offhand I can think of three reasons. Either ...

... those forms are never evaluated. You could check this by putting a
    (progn (message "Huhu!") (sit-for 10))
    right before them and then start Emacs again.

... or, as you suggested, they are evaluated, but something changes
    the keymap after that.

... or psgml-mode doesn't use `sgml-mode-map'. Maybe `psgml-mode-map'?

>
> I tried each of these, reloading emacs each time.  Question: Putting the
> cursor after the closing parenthesis of each (1 - 4) and doing C-x C-e
> would accomplish the same thing, yes?

Yes.  You could try that with #1 or #2.

[...]

> load-path's value is 
[load-path]

> It looks like psgml being loaded twice.

That's no problem.  Emacs takes the first entry in the list, where it
finds the required package.

[...]
> Letzte Nachrichten:  I pulled this out of the old bag of tricks and it 
> worked:
>
> (global-set-key "\M-e" 'my-html-forward-sentence)
>
> Yes, I'd prefer that this keybinding be in effect only in buffers using
> html-helper-mode (which, I know, is what you're aiming at).  But booking 
> passage there hasn't seemed possible.

Hmm, I am not familiar with all those SGML/HTML/XML-editing-mode. Is
`html-helper-mode' a package different from psgml? Maybe there is an
`html-helper-mode-map'?

>>
> Now I need something to fill in the hole in the complement for the 
> above:
>
> (global-set-key "\M-a" 'my-html-backward-sentence)
>
> something like:
>
> ;;Find the begin of a sentence, e.g., "</p>Begin" or ".  Begin"
> (defun my-html-backward-sentence ()
>   (interactive)
>   (save-match-data
>     (if (re-search-backward "\\(>\\)[ ,AZ]\\|[.?!] " nil t)
>       (toggle-case-fold-search)

`toggle-case-fold-search' will toggle `case-fold-search' globally,
each time, the search is successful.  If you want to bind it to
another value temporarily, use a `let' binding:

(let ((case-fold-search t)) ... )

>       (re-search-forward "\\([A-Z]\\)" nil t))
>     (forward-char 1)))


I would use the same technique again:

(defun my-html-backward-sentence ()
  (interactive)
  (save-match-data
    (if (re-search-backward ">\\([[:alpha:]\\s-*]\\|[.?!]\\)" nil t)
        (goto-char (match-beginning 1)) ; then: go to beginning of
                                        ; subexpression 1.
      (goto-char (point-min))))) ; else: go to point-min.

Hint: If you want to construct regexps for Emacs Lisp, M-x re-builder
makes this easy. It provides visual feedback on the regexp you are
constructing in the buffer, subexpressions included.


    Oliver
-- 
3 Ventôse an 211 de la Révolution
Liberté, Egalité, Fraternité!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]