unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* problems with overlays
@ 2007-04-24  9:56 Sebastian Meisel
  2007-04-24 18:51 ` Amy Templeton
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Meisel @ 2007-04-24  9:56 UTC (permalink / raw)
  To: Emacs Mailing List

Hallo,

I try to write a function to highlight the commas in a sentence. I have 
still some problems to determine the borders of the sentence. But most 
of all, I have problems to remove the overlays when I don't need them 
anymore. I need to distinguish them from other overlays in the buffer. I 
looked an the TeX-fold mode and it seemed using the category property it 
a good way to do that. But it doesn't work.

;; hightlight commatas
(defface gspell-highlight-commata-face
  '((((class color)) (:foreground "Red" :background "LightGreen" :bold t 
: underline: t)) (t (:bold t)))
  "Face used for a word accepted by Gspell.")

(defun gspell-highlight-commata-sentence ()
  "Hightlight commatas in the current senctence"
  (interactive)
  (let ((hier (point))
    (satz-grenze (concat "\\. \\|" paragraph-start))
    (satz-ende (buffer-end 1))
    (satz-anfang 0))
    (save-excursion
      (re-search-backward satz-grenze (- hier 100) t 1)
      (let ((satz-anfang (match-end 0)))
    (goto-char hier)
    (if (re-search-forward satz-grenze (+ hier 100) t 1)
        (setq satz-ende (+ (match-beginning 0) 1)))
    (goto-char satz-ende)
    'gspell-remove-comma-overlays
    (while (re-search-backward "," satz-anfang t)
      (let ((ov-start (match-beginning 0))
        (ov-end (match-end 0)))
        (let ((ov (make-overlay ov-start ov-end (current-buffer) t nil)))
          (overlay-put ov 'face 'gspell-highlight-commata-face)
          (overlay-put ov 'category 'gspell-comma)
    )))))))

(defun gspell-remove-comma-overlays ()
  "Remove all comma-overlays from buffer."   
  (interactive)
  (let ((start (buffer-end -1))
    (end (buffer-end 1)))
    (setq overlays (overlays-in start end))
    (while overlays
      (when (eq (overlay-get (car overlays) 'category) 'gspell-comma)
    (delete-overlay (car overlays))
    (setq overlays (cdr overlays))))))

Thanks for any hint.

Sebastian Meisel

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

* Re: problems with overlays
  2007-04-24  9:56 Sebastian Meisel
@ 2007-04-24 18:51 ` Amy Templeton
  0 siblings, 0 replies; 3+ messages in thread
From: Amy Templeton @ 2007-04-24 18:51 UTC (permalink / raw)
  To: help-gnu-emacs

Sebastian Meisel wrote:
> I have still some problems to determine the borders of the
> sentence.

This may seem obvious, and if so sorry to waste your time,
but have you looked at the function (sentence-end), which
basically determines where sentences end (surprisingly
enough)?

Amy

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

* Re: problems with overlays
@ 2007-04-25  6:39 martin rudalics
  0 siblings, 0 replies; 3+ messages in thread
From: martin rudalics @ 2007-04-25  6:39 UTC (permalink / raw)
  To: sebastianmeisel; +Cc: help-gnu-emacs

The following should work, but still overkills.

         ....
	(goto-char satz-ende)
	(gspell-remove-comma-overlays)
	(while (re-search-backward "," satz-anfang t)
	  (let ((ov (make-overlay (match-beginning 0) (match-end 0) nil t)))
	      (overlay-put ov 'face 'gspell-highlight-commata-face)
	      (overlay-put ov 'gspell-comma t))))))))

(defun gspell-remove-comma-overlays ()
   "Remove all comma-overlays from buffer."
   (interactive)
   (dolist (overlay (overlays-in (point-min) (point-max)))
     (when (overlay-get overlay 'gspell-comma)
       (delete-overlay overlay))))

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

end of thread, other threads:[~2007-04-25  6:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-25  6:39 problems with overlays martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2007-04-24  9:56 Sebastian Meisel
2007-04-24 18:51 ` Amy Templeton

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