unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "David De La Harpe Golden" <david.delaharpe.golden@gmail.com>
To: rms@gnu.org, emacs-devel@gnu.org
Subject: Re: Improving X selection?
Date: Sat, 2 Feb 2008 00:17:00 +0000	[thread overview]
Message-ID: <8e24944a0802011617k66c49283id9478dc3d5168bdf@mail.gmail.com> (raw)
In-Reply-To: <8e24944a0802011115h77423fd1p2eae15a1e46bca1a@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1134 bytes --]

On 01/02/2008, David De La Harpe Golden wrote:
> Another mail to follow about making select-active-regions work.

Problem with select-active-regions is obvious: if you want it to work
with both keyboard and mouse, it's not enough to reset the x11
selection when the mark is reset, it needs to be reset when the point
is reset too, or the selection and active region will drift out of
sync until the next mark reset.

All well and good, but how to fix it?

Well, I can naively introduce post-point-motion function (as
attached*), but it's kind of intrusive and a potential performance
problem, though probably unnoticeable on modern/fast
machines/networks.  There might  be a better way to do it?

(I thought about propagating selection when idle, but sudden selection
inaccuracy when you go too fast would be annoying. post-command-hook
doesn't work either (I think).  Not sure how else to do it.)

* Note that I'm not really up to speed on emacs internals, especially
the C side and GC requirements when calling lisp from C.

(Some mouse.el interactions need additional options too I think - yet
another mail to follow with them...)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: select-active-regions-when-point-moves-too.diff --]
[-- Type: text/x-diff; name=select-active-regions-when-point-moves-too.diff, Size: 5413 bytes --]

diff -NarU 10 emacs-exs/lisp/simple.el emacs/lisp/simple.el
--- emacs-exs/lisp/simple.el	2008-02-01 22:40:31.000000000 +0000
+++ emacs/lisp/simple.el	2008-02-01 23:31:52.000000000 +0000
@@ -3340,20 +3340,63 @@
    (transient-mark-mode
     (setq mark-active nil)
     (run-hooks 'deactivate-mark-hook))))
 
 (defcustom select-active-regions nil
   "If non-nil, an active region automatically becomes the window selection."
   :type 'boolean
   :group 'killing
   :version "23.1")
 
+
+;; Do we want to provide a general post-point-motion-hook ?
+;; Easily abused, would at least have to come with dire warning 
+;; about performance implications of anything added. 
+;;
+(defvar post-point-motion-hook nil
+  "Hook called after point movement.
+
+Keep hooks short, sweet and FAST, or better yet, don't use this
+at all. Hooks here should NOT try to affect point position, 
+unless you want recursive trouble.")
+
+(defun post-point-motion ()
+  "Internal Lisp function called after point movements.
+
+See e.g. `activate-mark-hook', `post-command-hook' and text properties
+`point-entered' / `point-left'  if you want to take action in 
+certain common point movement situations.
+
+`inhibit-point-motion-hooks' inhibits calling this 
+function and therefore anything it does. This function currently 
+just handles sending the highlighted regions to the window system 
+when the point is moved and `select-active-regions' is true"
+  
+  ;; Er. But Should inhibit-point-motion-hooks inhibit this?  I just
+  ;; about argued myself into thinking it shouldt - if it shouldn't,
+  ;; change in C code intervals.c/set_point_both(), not here.
+
+  (and select-active-regions 
+       (region-active-p)
+       interprogram-highlight-function
+       (funcall interprogram-highlight-function 
+		(buffer-substring (region-beginning) (region-end))))
+  ;; activate-mark-hook is defined in its docstring to run 
+  ;; after commands when the region may have changed, not just when 
+  ;; the mark activates. Does moving the point 
+  ;; and thus changing the region count as such a command - probably? 
+  (and (region-active-p)
+       (run-hooks 'activate-mark-hook))
+  ;;  if you want post-point-motion-hook above...
+  (run-hooks 'post-point-motion-hook))
+
+
 (defun set-mark (pos)
   "Set this buffer's mark to POS.  Don't use this function!
 That is to say, don't use this function unless you want
 the user to see that the mark has moved, and you want the previous
 mark position to be lost.
 
 Normally, when a new mark is set, the old one should go on the stack.
 This is why most applications should use `push-mark', not `set-mark'.
 
 Novice Emacs Lisp programmers often try to use the mark for the wrong
diff -NarU 10 emacs-exs/src/intervals.c emacs/src/intervals.c
--- emacs-exs/src/intervals.c	2008-02-01 22:41:39.000000000 +0000
+++ emacs/src/intervals.c	2008-02-01 23:16:00.000000000 +0000
@@ -2050,20 +2050,23 @@
   if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer))
     abort ();
 
   have_overlays = (buffer->overlays_before || buffer->overlays_after);
 
   /* If we have no text properties and overlays,
      then we can do it quickly.  */
   if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) && ! have_overlays)
     {
       temp_set_point_both (buffer, charpos, bytepos);
+      if (NILP (Vinhibit_point_motion_hooks) &&
+	  FUNCTIONP (intern ("post-point-motion")))
+	call0 (intern ("post-point-motion"));
       return;
     }
 
   /* Set TO to the interval containing the char after CHARPOS,
      and TOPREV to the interval containing the char before CHARPOS.
      Either one may be null.  They may be equal.  */
   to = find_interval (BUF_INTERVALS (buffer), charpos);
   if (charpos == BUF_BEGV (buffer))
     toprev = 0;
   else if (to && to->position == charpos)
@@ -2087,20 +2090,23 @@
   else if (buffer_point != BUF_PT (buffer))
     fromprev = from, from = 0;
   else
     fromprev = from;
 
   /* Moving within an interval.  */
   if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to)
       && ! have_overlays)
     {
       temp_set_point_both (buffer, charpos, bytepos);
+      if (NILP (Vinhibit_point_motion_hooks) &&
+	  FUNCTIONP (intern ("post-point-motion")))
+	call0 (intern ("post-point-motion"));
       return;
     }
 
   original_position = charpos;
 
   /* If the new position is between two intangible characters
      with the same intangible property value,
      move forward or backward until a change in that property.  */
   if (NILP (Vinhibit_point_motion_hooks)
       && ((! NULL_INTERVAL_P (to) && ! NULL_INTERVAL_P (toprev))
@@ -2236,20 +2242,25 @@
       	call2 (leave_after, make_number (old_position),
       	       make_number (charpos));
 
       if (! EQ (enter_before, leave_before) && !NILP (enter_before))
       	call2 (enter_before, make_number (old_position),
       	       make_number (charpos));
       if (! EQ (enter_after, leave_after) && !NILP (enter_after))
       	call2 (enter_after, make_number (old_position),
       	       make_number (charpos));
     }
+
+  if (NILP (Vinhibit_point_motion_hooks) &&
+      FUNCTIONP (intern ("post-point-motion")))
+    call0 (intern ("post-point-motion"));
+  
 }
 \f
 /* Move point to POSITION, unless POSITION is inside an intangible
    segment that reaches all the way to point.  */
 
 void
 move_if_not_intangible (position)
      int position;
 {
   Lisp_Object pos;

  reply	other threads:[~2008-02-02  0:17 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-15 10:20 Improving X selection? Horsley, Tom
2007-10-15 11:06 ` Jan Djärv
2007-10-16  4:10 ` Richard Stallman
2007-10-16 23:29   ` David De La Harpe Golden
2007-10-17  1:05     ` David De La Harpe Golden
2007-12-25 21:13     ` Richard Stallman
2008-01-28 19:52       ` David De La Harpe Golden
2008-01-29  0:59         ` David De La Harpe Golden
2008-02-01 19:15           ` David De La Harpe Golden
2008-02-02  0:17             ` David De La Harpe Golden [this message]
2008-02-03 11:38               ` David De La Harpe Golden
2008-02-03 12:44                 ` Jan D.
2008-02-03 13:12                   ` David De La Harpe Golden
2008-02-04 21:02                     ` David De La Harpe Golden
2008-02-05  3:38                       ` David De La Harpe Golden
2008-02-05  7:08                       ` Jan Djärv
2008-02-07  3:57                         ` David De La Harpe Golden
2008-02-07  4:23                           ` Miles Bader
2008-02-07  4:59                             ` David De La Harpe Golden
2008-02-07  9:07                           ` Jason Rumney
2008-02-07 16:32                             ` David De La Harpe Golden
2008-02-07 17:11                               ` David De La Harpe Golden
2008-02-07 17:13                               ` Jason Rumney
2008-02-07 19:46                                 ` Stefan Monnier
2008-02-10 18:42                                 ` Richard Stallman
2008-02-11 17:46                                   ` David De La Harpe Golden
2008-02-07 17:25                               ` Stefan Monnier
2008-02-07 17:39                                 ` David De La Harpe Golden
2008-02-07 17:51                                   ` David De La Harpe Golden
2008-02-07 19:54                                   ` Stefan Monnier
2008-02-07 15:14                           ` Stefan Monnier
2008-02-07 16:15                             ` David De La Harpe Golden
2008-02-07 18:01                               ` Stephen J. Turnbull
2008-02-07 18:07                                 ` David De La Harpe Golden
2008-02-07 19:21                                   ` Stephen J. Turnbull
2008-02-08  1:19                                     ` Miles Bader
2008-02-08  1:42                                       ` David De La Harpe Golden
2008-02-07 18:22                                 ` David De La Harpe Golden
2008-02-07 19:45                                   ` Stefan Monnier
2008-02-07 20:39                                     ` David De La Harpe Golden
2008-02-07 21:25                                       ` Stephen J. Turnbull
2008-02-07 21:41                                         ` David De La Harpe Golden
2008-02-08  0:22                                           ` Stephen J. Turnbull
2008-02-08  1:26                                             ` David De La Harpe Golden
2008-02-07 22:43                                       ` Stefan Monnier
2008-02-08  2:50                                         ` David De La Harpe Golden
2008-02-08 13:26                                           ` OT [was Re: Improving X selection?] Tom Horsley
2008-02-08 15:30                                             ` David De La Harpe Golden
2008-02-08 16:07                                               ` OT Stefan Monnier
2008-02-08 16:43                                                 ` OT David De La Harpe Golden
2008-02-08 14:41                                           ` Improving X selection? Stefan Monnier
2008-02-08 15:21                                             ` David De La Harpe Golden
2008-02-17  3:38                                             ` David De La Harpe Golden
2008-02-17  3:55                                               ` David De La Harpe Golden
2008-02-07 21:01                                     ` Tom Horsley
2008-02-07 21:18                                       ` David De La Harpe Golden
2008-02-07 21:36                                         ` Tom Horsley
2008-02-07 21:40                                           ` David De La Harpe Golden
2008-02-07 22:51                                       ` Stefan Monnier
     [not found]                                 ` <8e24944a0802071042u43d68f04pc8492ad8ce07aa18@mail.gmail.com>
2008-02-07 18:44                                   ` Fwd: " David De La Harpe Golden
2008-02-03 16:18             ` Richard Stallman
2008-02-03 18:29               ` David De La Harpe Golden
2008-02-05  5:58               ` David De La Harpe Golden
2008-02-05  6:23                 ` Miles Bader
2008-02-05  6:56                   ` David De La Harpe Golden
2008-02-03 16:18           ` Richard Stallman
     [not found] <20071012105022.6c8b174a@tweety>
2007-10-14 16:29 ` Richard Stallman
2007-10-14 17:25   ` Jeremy Maitin-Shepard
2007-10-15  6:19     ` Jan Djärv
2007-10-15  6:21       ` Jan Djärv
2007-10-15  6:41       ` Eli Zaretskii
2007-10-15  6:55       ` Miles Bader
2007-10-15  8:16         ` Jan Djärv
2007-10-15 14:21       ` Stefan Monnier
2007-10-15 18:30       ` Richard Stallman
2007-10-15 19:26         ` Jeremy Maitin-Shepard
2007-10-15 20:03           ` Andreas Schwab
2007-10-15 20:22             ` Jeremy Maitin-Shepard
2007-10-16  8:02               ` Frank Schmitt
2007-10-16  7:27           ` Jan Djärv
2007-10-16 10:08             ` René Kyllingstad
2007-10-16 13:15               ` Stefan Monnier
2008-08-18 15:29                 ` René Kyllingstad
2008-08-18 18:47                   ` David De La Harpe Golden
2008-08-18 19:16                 ` David Hansen
2008-08-19  8:06                   ` Frank Schmitt
2008-08-25 15:34                     ` Juri Linkov
2008-08-25 15:56                       ` Frank Schmitt
2008-08-28 17:45                         ` David De La Harpe Golden
2008-08-28 17:58                           ` Frank Schmitt
2008-08-28 18:19                             ` David De La Harpe Golden
2008-08-29  5:53                               ` David Hansen
2008-08-30  4:08                                 ` David De La Harpe Golden
2008-08-31  7:41                                   ` David Hansen
2008-08-20 22:41                   ` David De La Harpe Golden
2008-08-25 15:34                     ` Juri Linkov
2008-08-26  3:09                       ` David Hansen
2008-08-26  8:03                         ` David De La Harpe Golden
2008-08-26  8:41                           ` David Hansen
2007-10-16  7:26         ` Jan Djärv

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=8e24944a0802011617k66c49283id9478dc3d5168bdf@mail.gmail.com \
    --to=david.delaharpe.golden@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=rms@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 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).