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: gebser
Subject: Re: What's a better regexp for 'sentence-end' variable??
Date: Fri, 21 Feb 2003 05:37:45 -0500 (EST)

Oliver,

Merci vielmals nochmal for the Beihilfe.

Oliver Scholz at 12:35 (UTC+0100) on Thu, 20 Feb 2003 said:

= gebser@ameritech.net writes:
= 
= > Oliver Scholz at 15:06 (UTC+0100) on Tue, 18 Feb 2003 said:
= [...]
= > = What is the `purecopy' in your code good for? You didn't change this
= > = in the source code, did you? ;-)
= >
= > Ya got me.  That's what's used in paragraphs.el where "sentence-end" is 
= > defined.
= 
= 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. Even if it would be
= absolutely necessary to change a function's definition (it almost
= never is), you would be better off to copy it into your .emacs and
= change it there.

You're right.  But it's the hacker in me that likes to just go in and
change things... why gnu and linux stuff is so cool.  I've been doing
this for years and it seems to work for me most of the time.  True, it
isn't necessary.  But if I copied off every bit of code I changed and
put it in my .emacs, my .emacs would be huge.  It's already too big.  
I've even cut off large chunks of it and put it into a separate file in
site-lisp, occasionally compiling it.  I suppose that would be the best
practice.

The worst part about changing the original is that I lose my changes 
when I upgrade.  (Actually, I save off the old versions until I can copy 
in my personal customizations.)

For this problem I'm putting code into .emacs:

...
; Needed for defun my-html-forward-sentence below
(require 'sgml-mode)

;;Find the end of an html sentence, e.g., "end.</p>".
(defun my-html-forward-sentence ()
  (interactive)
  (save-match-data
    (if (re-search-forward "\\([.?!]\\)[<\t\n ]" nil t)
        (goto-char (match-end 1))
      (goto-char (point-max)))))

;;The above works... have to do M-x my-html-forward-sentence RETURN

;;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))

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

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?


= 
= If you want to modify `sentence-end' you can simply put something like
= this into your .emacs:

It doesn't back up a character (to get before the '<') like yours does.


= 
= (setq sentence-end "Your new regexp")
= 
= 
= > [modifying `sgml-mode-map']
= 
= > This didn't go.  An error told me that I don't have the path (to psgml).  
= > I haven't been able to figure that one out yet.
= [...]
= 
= Psgml is an add-on package that doesn't ship with stock Emacs. What is
= the exakt error message that tells you that psgml is not in the path?

For the life of me, I don't recall how I came to that.  I've been trying 
to get it back for the past hour+.  Maybe I changed something yesterday 
which resolved that.  And looking below, it seems that psgml is being 
loaded now.


= What is the value of `load-path'? (Try `C-h v load-path RET') Where is
= psgml installed?

load-path's value is 
("/usr/share/emacs/site-lisp/tramp/lisp/" 
"/usr/share/emacs/20.7/site-lisp" "/usr/share/emacs/site-lisp" 
"/usr/share/emacs/site-lisp/apel" "/usr/share/emacs/site-lisp/egg" 
"/usr/share/emacs/site-lisp/flim" "/usr/share/emacs/site-lisp/lang" 
"/usr/share/emacs/site-lisp/mew" "/usr/share/emacs/site-lisp/psgml" 
"/usr/share/emacs/site-lisp/semi" 
"/usr/share/emacs/site-lisp/site-start.d" 
"/usr/share/emacs/site-lisp/tramp" 
"/usr/share/emacs/site-lisp/tramp-2.0.28" 
"/usr/share/emacs/site-lisp/wl" "/usr/share/emacs/site-lisp/egg/egg" 
"/usr/share/emacs/site-lisp/egg/its" 
"/usr/share/emacs/site-lisp/tramp/contrib" 
"/usr/share/emacs/site-lisp/tramp/info" 
"/usr/share/emacs/site-lisp/tramp/lisp" 
"/usr/share/emacs/site-lisp/tramp/test" 
"/usr/share/emacs/site-lisp/tramp/texi" 
"/usr/share/emacs/site-lisp/tramp/tramp2" 
"/usr/share/emacs/site-lisp/tramp-2.0.28/contrib" 
"/usr/share/emacs/site-lisp/tramp-2.0.28/info" 
"/usr/share/emacs/site-lisp/tramp-2.0.28/lisp" 
"/usr/share/emacs/site-lisp/tramp-2.0.28/test" 
"/usr/share/emacs/site-lisp/tramp-2.0.28/texi" 
"/usr/share/emacs/site-lisp/tramp-2.0.28/tramp2" 
"/usr/share/emacs/site-lisp/wl/utils" "/usr/share/emacs/20.7/leim" 
"/usr/share/emacs/20.7/lisp" "/usr/share/emacs/20.7/lisp/textmodes" 
"/usr/share/emacs/20.7/lisp/progmodes" "/usr/share/emacs/20.7/lisp/play" 
"/usr/share/emacs/20.7/lisp/mail" "/usr/share/emacs/20.7/lisp/language" 
"/usr/share/emacs/20.7/lisp/international" 
"/usr/share/emacs/20.7/lisp/gnus" "/usr/share/emacs/20.7/lisp/emulation" 
"/usr/share/emacs/20.7/lisp/emacs-lisp" 
"/usr/share/emacs/20.7/lisp/calendar" "/usr/share/emacs/site-lisp/psgml" 
"/usr/share/emacs/site-lisp/wl")

It looks like psgml being loaded twice.


= 
= As I said in my other answer, you probably need to `require' your
= HTML/SGML package before you modify `sgml-mode-map'.  If you use
= psgml, you probably have an expression like (require 'psgml) in your
= .emacs. (I am not sure, because I don't use psgml yet.) Make sure that
= the `define-key' part comes _after_ that.

(require 'sgml-mode) ; is what I have there.



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.


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)
      (re-search-forward "\\([A-Z]\\)" nil t))
    (forward-char 1)))

This isn't ready for prime time though.  Without a supportive 
understanding of tags, it'll remain a semi-reliable cludge.


Thanks again for your kind assistance,
ken






reply via email to

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