unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Stefan Monnier" <monnier+gnu/emacs@cs.yale.edu>
Cc: emacs-devel@gnu.org, monnier@cs.yale.edu,
	monnier+gnu/emacs@rum.cs.yale.edu
Subject: Re: popup menu support for smerge-mode
Date: Sun, 24 Aug 2003 10:42:38 -0400	[thread overview]
Message-ID: <200308241442.h7OEgcxV020578@rum.cs.yale.edu> (raw)
In-Reply-To: 20030824.150334.55506789.jet@gyve.org

> +(easy-menu-define smerge-mode-popup-menu smerge-mode-map
> +  "Popup menu for `smerge-mode'."
> +  '(nil
> +    ["Keep Current" smerge-keep-current-by-mouse :help "Use current (at point) version"]
> +    ["Keep All" smerge-keep-all :help "Keep all three versions"]
> +    ))

Why not just reuse the existing menu ?

>  (defun smerge-auto-leave ()
> -  (when (and smerge-auto-leave
> -	     (save-excursion (goto-char (point-min))
> -			     (not (re-search-forward smerge-begin-re nil t))))
> +  (smerge-remove-overlays)
> +  (when (and 
> +	 ;; 1. Are conflict existed?
> +	 ;; As the side effect, overlays are put.
> +	 (not (save-excursion 
> +		(goto-char (point-min))
> +		(let (matched)
> +		  (while (smerge-find-conflict nil t)
> +		    (setq matched t))
> +		  matched)))
> +	 ;; 2. Check customize option.
> +	 smerge-auto-leave)
>      (smerge-mode -1)))

This is clearly wrong.  smerge-auto-leave is about leaving smerge-mode
when all conflicts are resolved.  It shouldn't fiddle with overlays at all.
The overlays should be removed by the call to (smerge-mode -1).

> +(defun smerge-put-overlay (start end)
> +  "Put overlay of smerge-mode between START and END.
> +The overlay has its own keymap to show popup menu."
> +  (setq overlay (make-overlay start end))

You're modifying a global `overlay' variable here.  Please let-bind it.

> +  (overlay-put overlay 'mouse-face 'highlight)

Having tried it, I'm not sure whether this is a good idea or not:
when the conflict is large, you end up with the whole window flashing
in `highlight' face in a very annoying way.

> +  (overlay-put overlay 'keymap (let ((km (make-sparse-keymap)))
> +				 (define-key km [down-mouse-3]
> +				   (lambda () (interactive)
> +				     (popup-menu smerge-mode-popup-menu)))
> +				 km))
> +  (overlay-put overlay 'help-echo "down-mouse-3: Use current (at point) version")

The help-echo is wrong: mouse-3 does not select the version under the
cursor (it pops up a menu instead).

> +(defun smerge-remove-overlays ()
> +  "Delete all overlays made by  `smerge-put-overlay'."
> +  (mapcar (lambda (o) (delete-overlay o)) smerge-overlays)
> +  (setq smerge-overlays nil))

When the output of `mapcar' is not used you should use `mapc'.
(lambda (x) (f x)) should always be replaced by 'f.

> +	  (when put-overlay
> +	    (if (and base-start base-end)
> +		(smerge-put-overlay base-start base-end))
> +	    (if (and mine-start mine-end)
> +		(smerge-put-overlay mine-start mine-end))
> +	    (if (and other-start other-end)
> +		(smerge-put-overlay other-start other-end)))

If base-start = base-end you end up with an empty overlay that the
user cannot click on.  It's simpler to just place a single overlay over
the whole conflict (including markers).

Also, I'm not sure it's a good idea to have a `match' function add an
overlay like that.  Matching is not supposed to have such side effects.
It's probably better to let the few callers that need it call
smerge-put-overlay themselves.


	Stefan

  reply	other threads:[~2003-08-24 14:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-10 12:16 popup menu support for smerge-mode Masatake YAMATO
2003-01-11 19:41 ` Stefan Monnier
2003-08-24  6:03   ` Masatake YAMATO
2003-08-24 14:42     ` Stefan Monnier [this message]
2003-09-18  8:54       ` Masatake YAMATO
2003-09-18 15:27         ` Stefan Monnier
2003-09-19  9:25           ` Masatake YAMATO
2003-09-19 15:57             ` Stefan Monnier
2003-09-26  7:58               ` Masatake YAMATO
2003-09-26  8:44                 ` Miles Bader
2003-09-26  8:53                   ` Behavior of evaporate Masatake YAMATO
2003-09-26  9:05                     ` Miles Bader
2003-09-26  9:17                     ` David Kastrup
2003-09-26 15:59                       ` Stefan Monnier
2003-09-27  2:31                       ` Richard Stallman
2003-09-30 20:56                         ` Alex Schroeder
2003-10-20 21:23                 ` popup menu support for smerge-mode Stefan Monnier
2004-03-10  4:32                   ` Masatake YAMATO
2004-03-11  7:00                   ` Masatake YAMATO
2003-10-14  3:59               ` Masatake YAMATO

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=200308241442.h7OEgcxV020578@rum.cs.yale.edu \
    --to=monnier+gnu/emacs@cs.yale.edu \
    --cc=emacs-devel@gnu.org \
    --cc=monnier+gnu/emacs@rum.cs.yale.edu \
    --cc=monnier@cs.yale.edu \
    /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).