emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fbbb9148cc: Minor fixes to Haiku selection support


From: Po Lu
Subject: master fbbb9148cc: Minor fixes to Haiku selection support
Date: Mon, 28 Mar 2022 08:31:29 -0400 (EDT)

branch: master
commit fbbb9148ccb63f0eccd032f9e7c8e585997d4185
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Minor fixes to Haiku selection support
    
    * lisp/term/haiku-win.el (haiku-selection-bounds): New function.
    (haiku-dnd-convert-string, haiku-select-encode-xstring)
    (haiku-select-encode-utf-8-string): Handle position pairs
    correctly.
    (gui-backend-set-selection): Adjust for new airity.
    * src/haikuselect.c (Fhaiku_selection_put): Fix arity.
---
 lisp/term/haiku-win.el | 48 +++++++++++++++++++++++++++++++++++++++++++++---
 src/haikuselect.c      |  2 +-
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el
index fcf3c4e383..f9dcd0d192 100644
--- a/lisp/term/haiku-win.el
+++ b/lisp/term/haiku-win.el
@@ -72,10 +72,40 @@ content that is being put into the selection by
 `gui-set-selection'.  See the doc string of `haiku-drag-message'
 for more details on the structure of the associations.")
 
+(defun haiku-selection-bounds (value)
+  "Return bounds of selection value VALUE.
+The return value is a list (BEG END BUF) if VALUE is a cons of
+two markers or an overlay.  Otherwise, it is nil."
+  (cond ((bufferp value)
+        (with-current-buffer value
+          (when (mark t)
+            (list (mark t) (point) value))))
+       ((and (consp value)
+             (markerp (car value))
+             (markerp (cdr value)))
+        (when (and (marker-buffer (car value))
+                   (buffer-name (marker-buffer (car value)))
+                   (eq (marker-buffer (car value))
+                       (marker-buffer (cdr value))))
+          (list (marker-position (car value))
+                (marker-position (cdr value))
+                (marker-buffer (car value)))))
+       ((overlayp value)
+        (when (overlay-buffer value)
+          (list (overlay-start value)
+                (overlay-end value)
+                (overlay-buffer value))))))
+
 (defun haiku-dnd-convert-string (value)
   "Convert VALUE to a UTF-8 string and appropriate MIME type.
 Return a list of the appropriate MIME type, and UTF-8 data of
 VALUE as a unibyte string, or nil if VALUE was not a string."
+  (unless (stringp value)
+    (when-let ((bounds (haiku-selection-bounds value)))
+      (setq value (ignore-errors
+                    (with-current-buffer (nth 2 bounds)
+                      (buffer-substring (nth 0 bounds)
+                                        (nth 1 bounds)))))))
   (when (stringp value)
     (list "text/plain" (string-to-unibyte
                         (encode-coding-string value 'utf-8)))))
@@ -143,7 +173,13 @@ CLIPBOARD should be the symbol `PRIMARY', `SECONDARY' or
   "Convert VALUE to a system message association.
 VALUE will be encoded as Latin-1 (like on X Windows) and stored
 under the type `text/plain;charset=iso-8859-1'."
-  (when (stringp value)
+  (unless (stringp value)
+    (when-let ((bounds (haiku-selection-bounds value)))
+      (setq value (ignore-errors
+                    (with-current-buffer (nth 2 bounds)
+                      (buffer-substring (nth 0 bounds)
+                                        (nth 1 bounds)))))))
+  (when (and (stringp value) (not (string-empty-p value)))
     (list "text/plain;charset=iso-8859-1" 1296649541
           (encode-coding-string value 'iso-latin-1))))
 
@@ -151,7 +187,13 @@ under the type `text/plain;charset=iso-8859-1'."
   "Convert VALUE to a system message association.
 VALUE will be encoded as UTF-8 and stored under the type
 `text/plain'."
-  (when (stringp value)
+  (unless (stringp value)
+    (when-let ((bounds (haiku-selection-bounds value)))
+      (setq value (ignore-errors
+                    (with-current-buffer (nth 2 bounds)
+                      (buffer-substring (nth 0 bounds)
+                                        (nth 1 bounds)))))))
+  (when (and (stringp value) (not (string-empty-p value)))
     (list "text/plain" 1296649541
           (encode-coding-string value 'utf-8-unix))))
 
@@ -173,7 +215,7 @@ VALUE will be encoded as UTF-8 and stored under the type
         (let ((result (funcall encoder type value)))
           (when result
             (push result message))))
-      (haiku-selection-put type message nil))))
+      (haiku-selection-put type message))))
 
 (cl-defmethod gui-backend-selection-exists-p (selection
                                               &context (window-system haiku))
diff --git a/src/haikuselect.c b/src/haikuselect.c
index 461482fea1..c1c619ee8c 100644
--- a/src/haikuselect.c
+++ b/src/haikuselect.c
@@ -112,7 +112,7 @@ haiku_unwind_clipboard_lock (int clipboard)
 }
 
 DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put,
-       3, 4, 0,
+       2, 4, 0,
        doc: /* Add or remove content from the clipboard CLIPBOARD.
 CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'.  NAME
 is a MIME type denoting the type of the data to add.  DATA is the



reply via email to

[Prev in Thread] Current Thread [Next in Thread]