Subject: bug#9678: closed (Re: bug#11319: [PATCH 1/2] BUGFIX: select current-diff-comparison regions for ediff-inferior-compare-regions correctly)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 14 Dec 2012 15:25:03 +0000

Your bug report

#11319: 24.0.50; ediff-inferior-compare-regions ignores user response for ediff buffer selection

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
11319: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11319
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#11319: [PATCH 1/2] BUGFIX: select current-diff-comparison regions for ediff-inferior-compare-regions correctly
From: Stefan Monnier <[email-masked]>
To: Dave Abrahams <[email-masked]>
Cc: Michael Kifer <[email-masked]>, [email-masked]
Date: Fri, 14 Dec 2012 10:23:53 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 24.4

> The buffer types passed to
> ediff-clone-buffer-for-current-diff-comparison are used to select the
> character ranges that participate in the inferior comparison.  Those
> were being hardcoded as 'A and 'B, which was wrong.

Thank you, it looks OK, so I installed it in trunk,

        Stefan

Subject: 24.0.50; ediff-inferior-compare-regions ignores user response for ediff buffer selection
From: Brent Goodrick <[email-masked]>
To: [email-masked]
Date: Wed, 5 Oct 2011 17:32:05 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

This bug report will be sent to the Free Software Foundation,
not to your local site managers!
Please write in English if possible, because the Emacs maintainers
usually do not have translators to read other languages for them.

Your report will be posted to the [email-masked] mailing list
and the gnu.emacs.bug news group, and at http://debbugs.gnu.org.

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug.  If you can, give
a recipe starting from `emacs -Q':

How to reproduce:

1. Open up three separate buffers.

2. Add the same content into all three buffers, except arrange for the
content to be different on all three buffers on one of the lines (This
is just to get a difference to run through
`ediff-inferior-compare-regions').

3. Run `ediff-buffers3' and select each of the three buffers

4. Type 'n' to go to the first difference.

5. Type '=' t run `ediff-inferior-compare-regions'

6. When prompted for "Enter the 1st buffer you want to compare",
answer with 'a'.

7. When prompted for "Enter the 2nd buffer you want to compare" ,
answer with 'c'. 

8. When prompted for "Compare currently highlighted difference
regions?" answer with 'y'.

9. Notice that the new ediff session has the region for the B buffer
and not the C buffer.

My analysis: I believe the bug is the hardcoding of 'A and 'B
buf-types in both calls to
`ediff-clone-buffer-for-current-diff-comparison' made inside the
`ediff-inferior-compare-regions' function here:

		   (ediff-clone-buffer-for-current-diff-comparison
		    bufA 'A "-Region.A-")

And here:

		   (ediff-clone-buffer-for-current-diff-comparison
		    bufB 'B "-Region.B-")

Here is a possible fixed version of the function where I introduced
the buf-type-A and buf-type-B local variables to store the 'A, 'B, or
'C symbols corresponding to the users selection, and used those values
in the calls to `ediff-clone-buffer-for-current-diff-comparison':

(defun ediff-inferior-compare-regions ()
  "Compare regions in an active Ediff session.
Like ediff-regions-linewise but is called from under an active Ediff session on
the files that belong to that session.

After quitting the session invoked via this function, type C-l to the parent
Ediff Control Panel to restore highlighting."
  (interactive)
  (let ((answer "")
	(possibilities (list ?A ?B ?C))
	(zmacs-regions t)
	use-current-diff-p
	begA begB endA endB bufA bufB buf-type-A buf-type-B)
    (if (ediff-valid-difference-p ediff-current-difference)
	(progn
	  (ediff-set-fine-diff-properties ediff-current-difference 'default)
	  (ediff-unhighlight-diff)))
    (ediff-paint-background-regions 'unhighlight)
    (flet ((char-to-buf-type (char)
			     (cond ((eq char ?A) 'A)
				   ((eq char ?B) 'B)
				   ((eq char ?C) 'C)
				   (t
				    (error "Assertion failed: invalid character %S" char)))))
      (cond ((ediff-merge-job)
	     (setq bufB ediff-buffer-C)
	     ;; ask which buffer to compare to the merge buffer
	     (while (cond ((eq answer ?A)
			   (setq bufA ediff-buffer-A
				 possibilities '(?B)
				 buf-type-B (char-to-buf-type answer))
			   nil)
			  ((eq answer ?B)
			   (setq bufA ediff-buffer-B
				 possibilities '(?A)
				 buf-type-B (char-to-buf-type answer))
			   nil)
			  ((equal answer ""))
			  (t (beep 1)
			     (message "Valid values are A or B")
			     (sit-for 2)
			     t))
	       (let ((cursor-in-echo-area t))
		 (message
		  "Which buffer to compare to the merge buffer (A or B)? ")
		 (setq answer (capitalize (read-char-exclusive))))))
	    ((ediff-3way-comparison-job)
	     ;; ask which two buffers to compare
	     (while (cond ((memq answer possibilities)
			   (setq possibilities (delq answer possibilities))
			   (setq bufA
				 (eval
				  (ediff-get-symbol-from-alist
				   answer ediff-buffer-alist)))
			   (setq buf-type-A (char-to-buf-type answer))
			   nil)
			  ((equal answer ""))
			  (t (beep 1)
			     (message
			      "Valid values are %s"
			      (mapconcat 'char-to-string possibilities " or "))
			     (sit-for 2)
			     t))
	       (let ((cursor-in-echo-area t))
		 (message "Enter the 1st buffer you want to compare (%s): "
			  (mapconcat 'char-to-string possibilities " or "))
		 (setq answer (capitalize (read-char-exclusive)))))
	     (setq answer "") ; silence error msg
	     (while (cond ((memq answer possibilities)
			   (setq possibilities (delq answer possibilities))
			   (setq bufB
				 (eval
				  (ediff-get-symbol-from-alist
				   answer ediff-buffer-alist)))
			   (setq buf-type-B (char-to-buf-type answer))
			   nil)
			  ((equal answer ""))
			  (t (beep 1)
			     (message
			      "Valid values are %s"
			      (mapconcat 'char-to-string possibilities " or "))
			     (sit-for 2)
			     t))
	       (let ((cursor-in-echo-area t))
		 (message "Enter the 2nd buffer you want to compare (%s): "
			  (mapconcat 'char-to-string possibilities "/"))
		 (setq answer (capitalize (read-char-exclusive))))))
	    (t ; 2way comparison
	     (setq bufA ediff-buffer-A
		   bufB ediff-buffer-B
		   possibilities nil))))
    (if (and (ediff-valid-difference-p ediff-current-difference)
	     (y-or-n-p "Compare currently highlighted difference regions? "))
	(setq use-current-diff-p t))
    (setq bufA (if use-current-diff-p
		   (ediff-clone-buffer-for-current-diff-comparison
		    bufA buf-type-A "-Region.A-")
		 (ediff-clone-buffer-for-region-comparison bufA "-Region.A-")))
    (ediff-with-current-buffer bufA
      (setq begA (region-beginning)
	    endA (region-end))
      (goto-char begA)
      (beginning-of-line)
      (setq begA (point))
      (goto-char endA)
      (end-of-line)
      (or (eobp) (forward-char)) ; include the newline char
      (setq endA (point)))
    (setq bufB (if use-current-diff-p
		   (ediff-clone-buffer-for-current-diff-comparison
		    bufB buf-type-B "-Region.B-")
		 (ediff-clone-buffer-for-region-comparison bufB "-Region.B-")))
    (ediff-with-current-buffer bufB
      (setq begB (region-beginning)
	    endB (region-end))
      (goto-char begB)
      (beginning-of-line)
      (setq begB (point))
      (goto-char endB)
      (end-of-line)
      (or (eobp) (forward-char)) ; include the newline char
      (setq endB (point)))
    (ediff-regions-internal
     bufA begA endA bufB begB endB
     nil     	     	     	; setup-hook
     (if use-current-diff-p	; job name
	 'ediff-regions-wordwise
       'ediff-regions-linewise)
     (if use-current-diff-p	; word mode, if diffing current diff
	 t nil)
     ;; setup param to pass to ediff-setup
     (list (cons 'ediff-split-window-function ediff-split-window-function)))))

I did not test the "ediff-merge-job" case but I suspect it also needs
to set the buf-type-A and buf-type-B variables. The 'char-to-buf-type'
local function could be written more concisely, but I could not find a
way to map a ?A character to a 'A symbol without resorting to a clunky
cond construct.

If Emacs crashed, and you have the Emacs process in the gdb debugger,
please include the output from the following gdb commands:
    `bt full' and `xbacktrace'.
For information about debugging Emacs, please read the file
/home/brentg/install/Linux.x86_64/share/emacs/24.0.50/etc/DEBUG.

In GNU Emacs 24.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.20.1)
 of 2011-01-15 on hungover
Windowing system distributor `The X.Org Foundation', version 11.0.10707000
configured using `configure  '--with-x-toolkit' '--with-xft' '--prefix=/home/brentg/install/Linux.x86_64''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Shell

Minor modes in effect:
  desktop-save-mode: t
  auto-insert-mode: t
  erc-ring-mode: t
  erc-services-mode: t
  erc-networks-mode: t
  shell-dirtrack-mode: t
  delete-selection-mode: t
  iswitchb-mode: t
  display-time-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: 1
  transient-mark-mode: t
  abbrev-mode: t

Recent input:
<return> r h y <tab> w <tab> <return> M-x r e p o r 
t - e m <tab> b <tab> <return>

Recent messages:
History item: 498
History item: 499
History item: 500
~ 
Completing command name...
Completed
Type C-x 1 to delete the help window.
mouse-2, RET: find function's definition
Renamed transient buffer "*Help*" to "*Help*<2>"
uncompressing ediff-util.el.gz...done

Load-path shadows:
/home/brentg/emacs_lisp_imported/slime/tree-widget hides /home/brentg/install/Linux.x86_64/share/emacs/24.0.50/lisp/tree-widget
/home/brentg/emacs_lisp_imported/remember/remember hides /home/brentg/install/Linux.x86_64/share/emacs/24.0.50/lisp/textmodes/remember
/home/brentg/emacs_lisp_imported/css-mode/css-mode hides /home/brentg/install/Linux.x86_64/share/emacs/24.0.50/lisp/textmodes/css-mode

Features:
(shadow mailalias bbdb-vm vm-autoload bbdb-snarf mail-extr rfc822
bbdb-com vm-rfaddons vm-message vm-macro multi-isearch emacsbug
ansi-color bg-emacs bg-desktop-setup conf-mode nxml-uchnm rng-xsd
xsd-regexp rng-cmpct vc-git skeleton desktop bg-customizations
bg-kmacro-setup bg-match-util bg-x-setup bg-ebrowse-setup ebrowse
ebuff-menu electric bg-init-program-setup bg-dos-batch-mode
bg-cmake-setup cmake-mode bg-quack-setup quack bg-qmake-setup
bg-allout-setup bg-gimp-mode-setup eldoc cmuscheme scheme gimp-mode
scheme-complete snippet autoinsert bg-edebug-setup edebug
bg-lisppaste-setup bg-instrument-util bg-calc-setup calc-ext calc
calc-loaddefs calc-macs bg-sudo-setup sudo bg-crontab-util bg-reminder
bg-wikipedia-mode-setup wikipedia-mode bg-outline-magic-mode-setup
outline-magic noutline outline bg-emacs-lisp-mode-setup bg-lisp-util
find-func bg-lisp-setup bg-stumpwm-setup stumpwm-mode
bg-css-mode-setup bg-gnuserv-setup gnuserv bg-compressed-files-setup
bg-apropos-mode-setup apropos bg-search-tcl bg-man-setup bg-env-setup
man assoc bg-visual-basic-mode-setup bg-regr-util bg-help-mode-setup
help-mode bg-diag bg-password-hiding-setup bg-browser-setup
bg-x-windows-util bg-perl-setup gud bg-perl-util bg-rectangle-setup
bg-picture-mode-setup bg-xml-setup rng-nxml rng-valid rng-loc rng-uri
rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns
nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc xmltok
bg-boxquote-setup boxquote bg-iswitchb-setup bg-outline-setup allout
bg-autosave-setup bg-mgc-specific-setup
bg-local-directory-registry-util bg-mail-abbrev-setup mailabbrev
uniquify ibuffer bg-planner-setup bg-planner-indexing
bg-planner-yank-link bg-planner-yank-link-man
bg-planner-yank-link-file bg-planner-yank-link-info bg-web-util mm-url
url url-proxy url-privacy url-expand url-methods url-history
url-cookie url-util url-parse auth-source netrc url-vars mailcap
bg-planner-yank-link-w3m bg-w3m-util
bg-search-object-regexp-instruction-list bg-search-object-simple
bg-search-object-none bg-planner-yank-link-base bg-search-object-base
bg-planner-elisp bg-remember-mode-setup remember-planner remember
bg-bbdb-setup bbdb-autoloads bbdb bg-planner-note-util
bg-elisp-unit-test-util bg-planner-util bg-muse-hacks image-file
planner-lisp planner-publish muse-xml planner cal-menu calendar
cal-loaddefs sort muse-colors bg-muse-setup bg-planner-abbrevs-setup
muse-html muse-xml-common cus-edit cus-start cus-load muse-publish
muse-project muse-protocols muse-regexps muse muse-nested-tags
muse-mode bg-cleanup-whitespace-at-point bg-planner-vars timeclock
bg-scrolling-setup bg-irc-setup erc-ring erc-join erc-services
erc-networks erc-dcc erc-fill erc-stamp erc-goodies erc erc-backend
erc-compat format-spec bg-ediff-setup bg-info-setup
bg-completion-list-mode-setup bg-global-key-mappings
bg-wrap-variable-util bg-rx-interactive bg-grep-setup bg-grep-group
grep bg-color-moccur-setup color-moccur bg-search-replace-util
bg-occur-mode-setup bg-find-file-setup bg-bookmark-definitions
bookmark pp bg-tabstop-definitions bg-mail-setup vm-w3m vm-pine
vm-mark vm-save vm-virtual vm-summary-faces vm-edit vm-imap vm-pop
vm-delete vm-digest vm-reply vm-toolbar vm-sort vm-undo vm-page
vm-motion vm-thread vm-mouse vm-minibuf vm-mime vm-menu tapestry
vm-window vm-crypto vm-summary vm-folder vm-misc vm vm-autoloads
vm-version vm-vars bg-encryption-setup dgpg generic epa-file epa
derived epg epg-config bg-w3m-setup edmacro kmacro w3m browse-url
doc-view jka-compr image-mode timezone w3m-hist w3m-fb bookmark-w3m
w3m-ems w3m-ccl ccl w3m-favicon w3m-image w3m-proc w3m-util supercite
regi smtpmail sendmail bg-gnus-definitions imap gnus gnus-ems nnheader
gnus-util mail-utils mm-util mail-prsvr wid-edit bg-octave-setup
bg-scm-setup bg-vc-util vc pcvs pcvs-parse pcvs-info pcvs-defs
bg-git-setup git log-edit easy-mmode pcvs-util add-log ewoc
bg-tcl-mode-setup bg-compile-setup bg-grep-compilation-util
bg-python-mode-setup python-21 python bg-buffer-menu-setup warnings
bg-makefile-mode-setup bg-shell-script-mode-setup sh-script executable
bg-dbx bg-gdb bg-gdb-util bg-javascript-setup js byte-opt bytecomp
byte-compile json imenu newcomment bg-java-setup bg-minibuffer-setup
bg-frame-definitions bg-vc-mode-setup vc-dispatcher
bg-dired-extensions bg-pdf-setup bg-pdf-util dired-aux dired
bg-forms-mode-setup forms-mode forms bg-isearch-setup bg-display-setup
bg-cc-mode-setup bg-debug-util bg-narrowing-setup bg-cxx-nav
bg-run-immediate bg-window-config-helper bg-id-utils-setup idutils
compile info bg-info-util bg-symbol-stack bg-cxx-util
bg-cxx-scan-debug-mode-base bg-basic-regexps-and-chars bg-p4-setup
p4-hacks p4 advice help-fns advice-preload bg-p4-completion
bg-p4-resolve bg-set-util bg-ediff-sparse-mode
bg-ediff-sparse-mode-base bg-p4-manual-apply-mode
bg-p4-manual-apply-mode-base bg-error-nav-util bg-rx-extra
bg-shell-mode-setup bg-shell-util bg-abbrev-skeleton-util
bg-background time-date bg-rlogin-setup rlogin shell comint ring
bg-open-file-at-point bg-p4-scan-mode bg-p4-scan-mode-base view
bg-button-mode-util bg-p4-basic-button bg-p4-util cc-mode cc-fonts
easymenu cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs
bg-pushfile-util bg-unit-test-util bg-elisp-debug-util elp perl-mode
mouse-sel thingatpt rect bg-delete-selection-mode-setup delsel
bg-utility iswitchb bg-file-cleanup bg-os-util bg-win32-utility
regexp-opt rx bg-win32-paths bg-linux-utility help-macro ediff-merg
ediff-diff ediff-wind ediff-help ediff-util ediff-mult ediff-init
ediff bg-coding-system-setup time bg-basic-setup bg-emacs-config cl
lisppaste-autoloads xml-rpc-autoloads package reporter tooltip
ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd
fontset image fringe lisp-mode register page menu-bar rfn-eshadow
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev loaddefs button minibuffer faces
cus-face files text-properties overlay md5 base64 format env
code-pages mule custom widget hashtable-print-readable backquote
make-network-process dbusbind dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)