all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joe Wells <jbw@macs.hw.ac.uk>
To: ehud@unix.mvs.co.il
Cc: emacs-devel@gnu.org
Subject: Re: no good way to highlight rectangle while region is highlighted
Date: Sat, 28 Jul 2007 01:10:26 +0100	[thread overview]
Message-ID: <86k5slwfpp.fsf@macs.hw.ac.uk> (raw)
In-Reply-To: <200707271943.l6RJhf8m010409@beta.mvs.co.il> (Ehud Karni's message of "Fri\, 27 Jul 2007 22\:43\:41 +0300")

"Ehud Karni" <ehud@unix.mvs.co.il> writes:

> On Fri, 27 Jul 2007 14:27:49, Joe Wells wrote:
>>
>> "Ehud Karni" <ehud@unix.mvs.co.il> writes:
>>
>> > The overlay is set to priority 99 and I sure see it OVER the region.
>>
>> How is this possible?  From (info "(elisp)Displaying Faces"):
>>
>>      "If these various sources together specify more than one face for a
>>   particular character, Emacs merges the attributes of the various faces
>                                ^^^^^^
>>   specified.  For each attribute, Emacs tries first the face of any
>>   special glyph; then the face for region highlighting, if appropriate;
>>   then the faces specified by overlays, followed by those specified by
>>   text properties, then the `mode-line' or `mode-line-inactive' or
>>   `header-line' face (if in a mode line or a header line), and last the
>>   `default' face."
>>
>> So the only faces which can override the "region" face are the faces
>> for glyphs set with display tables.  Overlays can't do that.  Because
>> the default "region" face sets a background color, there is no way an
>> overlay can override the background color of the region.
>
> I think the keyword is "merges" that you somehow ignored.

Hi, Ehud,

My reading of the documentation (supplemented by my perusal of the
Emacs C source code) for “merging” of face F1 and face F2 is that it
is not a symmetric operation and one of the faces takes priority.  In
the case of distinct face attributes, both are used; this means if
face F1 has value V1 for attribute A1 and face F2 has value V2 for
attribute A2, then you get a new face with V1 for A1 and V2 for A2.
In the case of assignments for the same face attribute, only one is
used; assuming face F1 has priority, if face F1 has value V1 for
attribute A0 and face F2 has value V2 for the same attribute A0, then
value V1 is used.

Note that there is no notion of merging of colors.  One of the two
colors is always used, unchanged.

My reading of the above-quoted documentation is that the “region” face
always takes priority over all overlays (regardless of the overlay's
“priority” property), text properties, and the default face.  Given
that the default value of the “region” face sets the :background
attribute, this means that any :background attribute set by any
overlay or text property or the default face is ignored in the area
covered by the region when it is being highlighted.

I have done testing that agrees with this.  Although I had no reason
to believe they would make any difference, I just now tried overlay
priorities anyway and verified that overlay priorities make no
difference whatsoever in this matter.  No matter how high the overlay
priority, the background color of the overlay's face can not override
the background color of the “region” face (and no attempt at color
combination occurs).  I even tried most-positive-fixnum as the overlay
priority (and you can't get any higher than that).

So basically, unless you are working with some Emacs C code which
differs from Emacs 22.1 in how this is handled, what you are saying
about overlay faces overriding the region face is simply not true.

My latest testing code is appended below, so you can check for
yourself.

>> Anyway, I couldn't try your code because it is incomplete.  As far as
>> I can tell, the entry point in what you supplied is mark-set-face and
>> this merely raises an error because there is no code to assign values
>> to the variables mark-1st and mark-2nd that it depends on.
>
> The code is a small part of a much larger (1320 lines) package.
>
> Here is sample code to set mark-1st to current cursor position.
> (setq mark-1st (cons
>                    (save-excursion (beginning-of-line) (point-marker))
>                    (col (1- (column-no)))))

I am only interested in seeing how it might be able to highlight the
current rectangle (simultaneously with the current region being
highlighted by Emacs's built in mechanism).  Do you have code to
illustrate that?  Right now, you are supplying less than what I
already have.

-- 
Joe

P.S.  Here is my testing code (which now tries to set a background
color for the overlay faces and sets the priority of these overlays as
high as possible):

;; I'm building on sense-region.el version 1.8 of 2002-05-23, because
;; I don't understand what version 1.9 is doing and all the
;; documentation is in Japanese and Google's translation doesn't make
;; much sense.  You can get version 1.8 in the recent Ubuntu versions
;; of the “sense-region” package (it is the only file in this .tar.gz
;; file):
;;
;;   http://archive.ubuntu.com/ubuntu/pool/universe/s/sense-region/sense-region_0.0.20020523.orig.tar.gz
;;
;; The file sense-region_2002-05-23.el on the author's web site is
;; actually a significantly later version from 2002-08-25, so don't get
;; that file.

;; *** TODO: Switch this to using the rectangle highlighting code from
;; cua-rect.el which now comes in Emacs (since 22.1).

(defun require-sense-region-if-found ()
  (or (require 'sense-region nil t)
      (require 'sense-region
               "/mnt/gentoo-portage/jbw/sense-region-0.0.20020523/sense-region.el"
               t)))

(require-sense-region-if-found)

(progn
  (make-face 'sense-region-face t)
  ;;(set-face-attribute 'sense-region-face nil :box '(:line-width -1 :color "red"))
  (set-face-attribute 'sense-region-face nil :box nil)
  ;;;; XOXOXOXO
  ;;;; OXOXOXOX
  ;;;; #o125 == #x55, #o252 == #xAA
  ;;(set-face-stipple 'sense-region-face '(8 2 "\125\252"))
  ;;;; XXO == 1 + 2 == 3
  ;;;; XOX == 1 + 4 == 5
  ;;;; OXX == 2 + 4 == 6
  ;;(set-face-stipple 'sense-region-face '(3 3 "\003\005\006"))
  ;;;; XOO == 1
  ;;;; OOX == 4
  ;;;; OXO == 2
  ;;(set-face-stipple 'sense-region-face '(3 3 "\001\004\002"))
  ;;;; XOOO == 1
  ;;;; OOOX == 8
  ;;;; OOXO == 4
  ;;;; OXOO == 2
  ;;(set-face-stipple 'sense-region-face '(4 4 "\001\010\004\002"))
  ;;;; XOOOO ==  1 == 001
  ;;;; OOOOX == 16 == 020
  ;;;; OOOXO ==  8 == 010
  ;;;; OOXOO ==  4 == 004
  ;;;; OXOOO ==  2 == 002
  ;;(set-face-stipple 'sense-region-face '(5 5 "\001\020\010\004\002"))
  ;;(set-face-stipple 'sense-region-face '(7 7 "\100\040\020\010\004\002\001"))
  (set-face-stipple 'sense-region-face '(8 8 "\200\100\040\020\010\004\002\001"))
  (set-face-stipple 'sense-region-face '(9 9 "\000\001\200\000\100\000\040\000\020\000\010\000\004\000\002\000\001\000"))
  (set-face-stipple 'sense-region-face '(11 11 "\000\004\000\002\000\001\200\000\100\000\040\000\020\000\010\000\004\000\002\000\001\000"))
  (set-face-stipple 'sense-region-face '(12 12 "\000\010\000\004\000\002\000\001\200\000\100\000\040\000\020\000\010\000\004\000\002\000\001\000"))
  ;;(set-face-stipple 'sense-region-face '(14 14 "\000\040\000\020\000\010\000\004\000\002\000\001\200\000\100\000\040\000\020\000\010\000\004\000\002\000\001\000"))
  ;;(set-face-inverse-video-p 'sense-region-face t)
  (set-face-inverse-video-p 'sense-region-face nil)
  ;;(set-face-foreground 'sense-region-face "red")
  (set-face-background 'sense-region-face nil)
  (set-face-background 'sense-region-face "red")
  (set-face-foreground 'sense-region-face nil)
  (setq sense-region-status 'rectangle))

(defadvice sense-region-on (around jbw-override-completely activate)
  (interactive)
  (if (featurep 'sense-region)
      (add-hook 'post-command-hook 'sense-region-redisplay)))

(defadvice sense-region-off (around jbw-override-completely activate)
  (interactive)
  (if (featurep 'sense-region)
      (sense-region-to-region))
  (remove-hook 'post-command-hook 'sense-region-redisplay))

(defadvice sense-region-to-region (around jbw-override-completely activate)
  (interactive)
  (mell-sign-rectangle-highlight-off sense-region-overlay-list)
  (setq sense-region-overlay-list nil))

(defadvice mell-transient-region-active-p (around jbw-handle-delayed-mark-deactivation activate)
  "Need to make sure (eq deactivate-mark t) taken as a sign the
region is not active (this is a bug in sense-region.el)."
  (if deactivate-mark
      nil
    ad-do-it))

;; This function is copied from version 1.8 of sense-region.el and
;; modified by inserting the commented sexp.
(defun mell-sign-rectangle-highlight (start end &optional buffer face)
  (save-excursion
    (or buffer (setq buffer (current-buffer)))
    (mapcar
     '(lambda (region)
	(prog1
	    (setq overlay
		  (make-overlay (car region) (cdr region) buffer nil t))
          ;; jbw: inserted next sexp (only difference from version 1.8)
          (overlay-put overlay 'priority most-positive-fixnum)
	  (overlay-put overlay 'face (or face 'highlight))
	  (overlay-put overlay 'evaporate t)
	  ))
     (mell-region-get-visible-rectangle-list start end))
;     (mell-region-get-rectangle-list start end))
    ))

  reply	other threads:[~2007-07-28  0:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-21 21:59 no good way to highlight rectangle while region is highlighted Joe Wells
2007-07-23  4:28 ` Richard Stallman
2007-07-23  7:46   ` Joe Wells
2007-07-23 22:30     ` Richard Stallman
2007-07-23 22:52       ` Joe Wells
2007-07-30 16:44         ` Richard Stallman
2007-07-30 17:04           ` Joe Wells
2008-01-23 21:25   ` overlays with higher priority than region [was: no good way to highlight rectangle while region is highlighted] Drew Adams
2007-07-23 17:55 ` no good way to highlight rectangle while region is highlighted Johan Bockgård
2007-07-26 16:59 ` Ehud Karni
2007-07-27  7:52   ` Joe Wells
2007-07-27  8:10     ` Ehud Karni
2007-07-27 13:27       ` Joe Wells
2007-07-27 19:43         ` Ehud Karni
2007-07-28  0:10           ` Joe Wells [this message]
2007-07-28 10:33             ` Ehud Karni
2007-07-27 13:36   ` Dan Nicolaescu

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86k5slwfpp.fsf@macs.hw.ac.uk \
    --to=jbw@macs.hw.ac.uk \
    --cc=ehud@unix.mvs.co.il \
    --cc=emacs-devel@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.