From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David De La Harpe Golden Newsgroups: gmane.emacs.devel Subject: select-active-regions xplat clean-up Date: Sun, 15 Nov 2009 01:49:10 +0000 Message-ID: <4AFF5E16.9080908@harpegolden.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070009000704040103070405" X-Trace: ger.gmane.org 1258249777 7413 80.91.229.12 (15 Nov 2009 01:49:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Nov 2009 01:49:37 +0000 (UTC) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 15 02:49:30 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N9UF6-0003Eo-D8 for ged-emacs-devel@m.gmane.org; Sun, 15 Nov 2009 02:49:29 +0100 Original-Received: from localhost ([127.0.0.1]:43328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N9UF5-0000wg-Lr for ged-emacs-devel@m.gmane.org; Sat, 14 Nov 2009 20:49:27 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N9UEy-0000uN-RV for emacs-devel@gnu.org; Sat, 14 Nov 2009 20:49:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N9UEu-0000rR-3o for emacs-devel@gnu.org; Sat, 14 Nov 2009 20:49:20 -0500 Original-Received: from [199.232.76.173] (port=46407 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N9UEt-0000rO-Uc for emacs-devel@gnu.org; Sat, 14 Nov 2009 20:49:15 -0500 Original-Received: from harpegolden.net ([65.99.215.13]:52862) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N9UEt-0008WJ-8p for emacs-devel@gnu.org; Sat, 14 Nov 2009 20:49:15 -0500 Original-Received: from [87.198.54.204] (87-198-54-204.ptr.magnet.ie [87.198.54.204]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id BBC7481FF for ; Sun, 15 Nov 2009 01:49:12 +0000 (GMT) User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:116996 Archived-At: This is a multi-part message in MIME format. --------------070009000704040103070405 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Removes unnecessary X11isms from simple.el, lays some groundwork for non-X11 implementation. Introduces clipboard-active-regions to cover case where users want select-active-regions like behaviour only affecting the clipboard instead (whether on X11 or platforms without primary). --------------070009000704040103070405 Content-Type: text/x-patch; name="select-active-regions_xplat_r1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions_xplat_r1.diff" Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.1029 diff -U 8 -r1.1029 simple.el --- lisp/simple.el 14 Nov 2009 16:07:47 -0000 1.1029 +++ lisp/simple.el 15 Nov 2009 01:36:31 -0000 @@ -2777,16 +2777,71 @@ kill ring for easy access via `yank-pop'. Note that the function should return a string only if a program other than Emacs has provided a string for pasting; if Emacs provided the most recent string, the function should return nil. If it is difficult to tell whether Emacs or some other program provided the current string, it is probably good enough to return nil if the string is equal (according to `string=') to the last text Emacs provided.") + +(defvar interprogram-region-function nil + "Function to call to make the active region available to other programs. + +Certain window systems provide a facility for directly insertion of +text currently selected in one program into another program. Such a +facility is sometimes confused with, but is nowadays considered +distinct from, a cut and paste clipboard type facility. The canonical +example is an X11 PRIMARY selection considered to be separate from and +independent to the X11 CLIPBOARD selection, as they are treated in +several X11 desktop environments. + +Emacs supports making its currently active region available to other +programs through the system facility for making the currently selected +text directly available, if any. Emacs also supports using the system +clipboard facility for doing so, as several non-X11 platforms have a +clipboard analog but no primary selection analog and some users find +it convenient to use the clipboard as a substitute for primary. + +If `select-active-regions' is non-nil, emacs will make the active +region available to other programs through the system facility for +making currently selected text directly available to other +applications. + +If `clipboard-active-regions' is non-nil, emacs will make the active +region available to other programs through the system clipboard +facility. + +This variable holds the function that Emacs calls to make the active +region available to other programs via the relevant facilities. The +function should be called with one or two arguments. + +Note that the function is not called every time the active region +changes, that could be every point movement while the region is +active: + +The first argument, TEXTORBUF, is either a string containing the text +which should be made available, or a buffer. If the argument is a +buffer, the function should arrange for the the region between the +mark and point in the buffer at such times as Emacs is expected to +provide the currently selected text by the system be made available, +and while emacs ownership of the relevant system facilities has not +lapsed, not at time of function call. This allows an acceptably efficient +lazy implementation on X11. On some non-X11 window systems, it may be +necessary to emulate lazy behaviour with an idle timer or other +technique, as the window system may not ask emacs for the currently +selected text but rather expect emacs to tell it the currently +selected text. + +The second, optional, argument, FORCE, if non-nil means that emacs +should update and acquire ownership of the relevant window system +facilities. If it is nil or not supplied, emacs should arrange to +update the relevant window system facilities only if it currently +already has ownership of them (emacs may have lost ownership to +another application since the previous call to the function).") ;;;; The kill ring data structure. (defvar kill-ring nil "List of killed text sequences. Since the kill ring is supposed to interact nicely with cut-and-paste @@ -3530,38 +3585,51 @@ If you are using this in an editing command, you are most likely making a mistake; see the documentation of `set-mark'." (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive) (marker-position (mark-marker)) (signal 'mark-inactive nil))) (defcustom select-active-regions nil - "If non-nil, an active region automatically becomes the window selection." + "If non-nil, an active region automatically becomes the window system current selection. + +The `interprogram-region-function', if any, implements this customization. + +See also `clipboard-active-regions'." :type 'boolean :group 'killing :version "23.1") -(declare-function x-selection-owner-p "xselect.c" (&optional selection)) +(defcustom clipboard-active-regions nil + "If non-nil, an active region automatically becomes the window system clipboard. + +The `interprogram-region-function', if any, implements this customization. + +See also `select-active-regions'." + :type 'boolean + :group 'killing + :version "23.2") ;; Many places set mark-active directly, and several of them failed to also ;; run deactivate-mark-hook. This shorthand should simplify. (defsubst deactivate-mark (&optional force) "Deactivate the mark by setting `mark-active' to nil. Unless FORCE is non-nil, this function does nothing if Transient Mark mode is disabled. This function also runs `deactivate-mark-hook'." (when (or transient-mark-mode force) - ;; Copy the latest region into the primary selection, if desired. - (and select-active-regions + ;; Copy the latest region into the primary selection + ;; and/or clipboard, if desired, via interprogram-region-function + (and (or select-active-regions clipboard-active-regions) mark-active - (display-selections-p) - (x-selection-owner-p 'PRIMARY) - (x-set-selection 'PRIMARY (buffer-substring-no-properties - (region-beginning) (region-end)))) + interprogram-region-function + (funcall interprogram-region-function + (buffer-substring-no-properties + (region-beginning) (region-end)) nil)) (if (and (null force) (or (eq transient-mark-mode 'lambda) (and (eq (car-safe transient-mark-mode) 'only) (null (cdr transient-mark-mode))))) ;; When deactivating a temporary region, don't change ;; `mark-active' or run `deactivate-mark-hook'. (setq transient-mark-mode nil) (if (eq (car-safe transient-mark-mode) 'only) @@ -3570,19 +3638,20 @@ (run-hooks 'deactivate-mark-hook)))) (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode (setq transient-mark-mode 'lambda)) - (when (and select-active-regions - (display-selections-p)) - (x-set-selection 'PRIMARY (current-buffer))))) + (when (and (or select-active-regions clipboard-active-regions) + interprogram-region-function) + (funcall interprogram-region-function + (current-buffer) t)))) (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. @@ -3595,19 +3664,19 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (when (and select-active-regions - (display-selections-p)) - (x-set-selection 'PRIMARY (current-buffer))) + (when (and (or select-active-regions clipboard-active-regions) + interprogram-region-function) + (funcall interprogram-region-function (current-buffer) t)) (set-marker (mark-marker) pos (current-buffer))) ;; Normally we never clear mark-active except in Transient Mark mode. ;; But when we actually clear out the mark value too, we must ;; clear mark-active in any mode. (deactivate-mark t) (set-marker (mark-marker) nil))) (defcustom use-empty-active-region nil Index: lisp/mouse.el =================================================================== RCS file: /sources/emacs/emacs/lisp/mouse.el,v retrieving revision 1.363 diff -U 8 -r1.363 mouse.el --- lisp/mouse.el 13 Nov 2009 22:19:53 -0000 1.363 +++ lisp/mouse.el 15 Nov 2009 01:36:31 -0000 @@ -1361,22 +1361,22 @@ (defun mouse-yank-at-click (click arg) "Insert the last stretch of killed text at the position clicked on. Also move point to one end of the text thus inserted (normally the end), and set mark at the beginning. Prefix arguments are interpreted as with \\[yank]. If `mouse-yank-at-point' is non-nil, insert at point regardless of where you click. -If `select-active-regions' is non-nil, the mark is deactivated -before inserting the text." +If `select-active-regions' or `clipboard-active-regions' are non-nil, +the mark is deactivated before inserting the text." (interactive "e\nP") ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) - (when select-active-regions + (when (or select-active-regions clipboard-active-regions) ;; Without this, confusing things happen upon e.g. inserting into ;; the middle of an active region. (deactivate-mark)) (or mouse-yank-at-point (mouse-set-point click)) (setq this-command 'yank) (setq mouse-selection-click-count 0) (yank arg)) Index: lisp/term/x-win.el =================================================================== RCS file: /sources/emacs/emacs/lisp/term/x-win.el,v retrieving revision 1.245 diff -U 8 -r1.245 x-win.el --- lisp/term/x-win.el 11 Nov 2009 05:49:14 -0000 1.245 +++ lisp/term/x-win.el 15 Nov 2009 01:36:31 -0000 @@ -1404,19 +1404,32 @@ ;; This code is still a big improvement because now the user can ;; futz with the current selection and get emacs to pay attention ;; to the cut buffer again (previously as soon as clipboard or ;; primary had been set the cut buffer would essentially never be ;; checked again). (or clip-text primary-text cut-text) ))) +(declare-function x-selection-owner-p "xselect.c" (&optional selection)) + +(defun x-region-handler (textorbuf &optional force) + "X implementation of `interprogram-region-function'" + (when (and select-active-regions + (or force (x-selection-owner-p 'PRIMARY))) + (x-set-selection 'PRIMARY textorbuf)) + (when (and clipboard-active-regions + (or force (x-selection-owner-p 'CLIPBOARD))) + (x-set-selection 'CLIPBOARD textorbuf))) + ;; Arrange for the kill and yank functions to set and check the clipboard. (setq interprogram-cut-function 'x-select-text) (setq interprogram-paste-function 'x-cut-buffer-or-selection-value) +;; Arrange for the active region to be propagated to system if desired. +(setq interprogram-region-function 'x-region-handler) (defun x-clipboard-yank () "Insert the clipboard contents, or the last stretch of killed text." (interactive "*") (let ((clipboard-text (x-selection-value 'CLIPBOARD)) (x-select-enable-clipboard t)) (if (and clipboard-text (> (length clipboard-text) 0)) (kill-new clipboard-text)) --------------070009000704040103070405--