[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A possible marker bug in emacs 20.4
From: |
Ehud Karni |
Subject: |
Re: A possible marker bug in emacs 20.4 |
Date: |
Wed, 7 Mar 2001 20:21:26 +0200 |
On Mon, 5 Mar 2001 11:56:29 -0800, Bingham, Jay <Jay.Bingham@compaq.com> wrote:
>
> I wrote a little procedure which removes text from a buffer. I wanted to
> enhance it to return point to its original position after it was finished
> removing all matches of the string. Here is the function:
>
> (defun trim-buffer ()
> (interactive)
> (let ((start-loc (make-marker)))
> (setq start-loc (point))
Here is your mistake, `point' returns a number, `point-marker' returns a
marker. The `setq' command REPLACES the (void) marker by a number.
The above should be:
(setq start-loc (point-marker))
> From the description of markers in the Elisp reference manual I assumed that
> start-loc would be adjusted when replace-match deleted the spaces, tabs, and
> carriage return characters from the buffer. This does not occur inside this
> function. When I create a test buffer, set mark in it, then use
> re-search-forward and replace-match from the eval prompt the marker
> arithmetic gets done. Is this a misunderstanding on my part of how/when the
> marker arithmetic is done or is this a bug?
As I explained above you mistook `point' for a marker.
Bellow is my function that is similar to yours but has some more options.
This function is used in my `write-file-hooks'.
Ehud.
(defvar save-options nil
"List of options to use when saving the file. possible values:
unstrip - do not strip white spaces from right of lines (default is strip)
tabify - tabify the whole file (use tabs instead of spaces)
untabify - opposite of tabify
This variable is local to the buffer.")
(setq-default save-options nil)
(make-variable-buffer-local 'save-options)
(defun included (elt list)
"Returns non-nil if ELT is an element of LIST. Comparison done with equal.
The value is actually the tail of LIST whose car is ELT or t for constant.
Same as memq, but works on symbols too, e.g (included 'cnst 'cnst) evals to t."
(if list
(if (listp list) ;here we differ from memq
(memq elt list) ;use memq (built-in)
(equal list elt)))) ;here we differ from memq
(defun strip-blanks-right () "Strip trailing blanks (for the whole file)"
(interactive)
(or buffer-read-only ;; do nothing if read only !
(let ((pos (point-marker)) ;; current position
(sbul buffer-undo-list)) ;; undo list
(goto-char (point-min))
(or find-file-literally ;; no strip if "literally"
(included 'unstrip save-options)
(eq major-mode 'rmail-mode)
(while (re-search-forward "[ \t]*\n" nil t)
(replace-match "\n" t t)))
(and (buffer-file-name)
(or (included 'tabify save-options)
(string= ".mak" (substring (buffer-file-name) -4)))
(tabify (point-min) (point-max)))
(and (included 'untabify save-options)
(untabify (point-min) (point-max)))
(setq buffer-undo-list sbul) ;; restore undo
(goto-char pos))) ;; restore position
nil ) ;;force returning of nil (successful)
--
@@@@@@ @@@ @@@@@@ @ @ Ehud Karni Simon & Wiesel Insurance agency
@ @ @ @@ @ Tel: +972-3-6212-757 Fax: +972-3-6292-544
@ @ @ @ @ @@ (USA) Fax and voice mail: 1-815-5509341
@ @ @ @ @ @ Better Safe Than Sorry
http://www.simonwiesel.co.il mailto:ehud@unix.simonwiesel.co.il