diff options
| author | Po Lu | 2022-03-28 12:28:53 +0000 |
|---|---|---|
| committer | Po Lu | 2022-03-28 12:28:53 +0000 |
| commit | fbbb9148ccb63f0eccd032f9e7c8e585997d4185 (patch) | |
| tree | 7262a1823022453d006b4636cf0ccbc89a559058 | |
| parent | dc0ee78d93c36606e7e8502d8ccff5f8c6116550 (diff) | |
| download | emacs-fbbb9148ccb63f0eccd032f9e7c8e585997d4185.tar.gz emacs-fbbb9148ccb63f0eccd032f9e7c8e585997d4185.zip | |
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.
| -rw-r--r-- | lisp/term/haiku-win.el | 48 | ||||
| -rw-r--r-- | 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 fcf3c4e383c..f9dcd0d1922 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 | |||
| 72 | `gui-set-selection'. See the doc string of `haiku-drag-message' | 72 | `gui-set-selection'. See the doc string of `haiku-drag-message' |
| 73 | for more details on the structure of the associations.") | 73 | for more details on the structure of the associations.") |
| 74 | 74 | ||
| 75 | (defun haiku-selection-bounds (value) | ||
| 76 | "Return bounds of selection value VALUE. | ||
| 77 | The return value is a list (BEG END BUF) if VALUE is a cons of | ||
| 78 | two markers or an overlay. Otherwise, it is nil." | ||
| 79 | (cond ((bufferp value) | ||
| 80 | (with-current-buffer value | ||
| 81 | (when (mark t) | ||
| 82 | (list (mark t) (point) value)))) | ||
| 83 | ((and (consp value) | ||
| 84 | (markerp (car value)) | ||
| 85 | (markerp (cdr value))) | ||
| 86 | (when (and (marker-buffer (car value)) | ||
| 87 | (buffer-name (marker-buffer (car value))) | ||
| 88 | (eq (marker-buffer (car value)) | ||
| 89 | (marker-buffer (cdr value)))) | ||
| 90 | (list (marker-position (car value)) | ||
| 91 | (marker-position (cdr value)) | ||
| 92 | (marker-buffer (car value))))) | ||
| 93 | ((overlayp value) | ||
| 94 | (when (overlay-buffer value) | ||
| 95 | (list (overlay-start value) | ||
| 96 | (overlay-end value) | ||
| 97 | (overlay-buffer value)))))) | ||
| 98 | |||
| 75 | (defun haiku-dnd-convert-string (value) | 99 | (defun haiku-dnd-convert-string (value) |
| 76 | "Convert VALUE to a UTF-8 string and appropriate MIME type. | 100 | "Convert VALUE to a UTF-8 string and appropriate MIME type. |
| 77 | Return a list of the appropriate MIME type, and UTF-8 data of | 101 | Return a list of the appropriate MIME type, and UTF-8 data of |
| 78 | VALUE as a unibyte string, or nil if VALUE was not a string." | 102 | VALUE as a unibyte string, or nil if VALUE was not a string." |
| 103 | (unless (stringp value) | ||
| 104 | (when-let ((bounds (haiku-selection-bounds value))) | ||
| 105 | (setq value (ignore-errors | ||
| 106 | (with-current-buffer (nth 2 bounds) | ||
| 107 | (buffer-substring (nth 0 bounds) | ||
| 108 | (nth 1 bounds))))))) | ||
| 79 | (when (stringp value) | 109 | (when (stringp value) |
| 80 | (list "text/plain" (string-to-unibyte | 110 | (list "text/plain" (string-to-unibyte |
| 81 | (encode-coding-string value 'utf-8))))) | 111 | (encode-coding-string value 'utf-8))))) |
| @@ -143,7 +173,13 @@ CLIPBOARD should be the symbol `PRIMARY', `SECONDARY' or | |||
| 143 | "Convert VALUE to a system message association. | 173 | "Convert VALUE to a system message association. |
| 144 | VALUE will be encoded as Latin-1 (like on X Windows) and stored | 174 | VALUE will be encoded as Latin-1 (like on X Windows) and stored |
| 145 | under the type `text/plain;charset=iso-8859-1'." | 175 | under the type `text/plain;charset=iso-8859-1'." |
| 146 | (when (stringp value) | 176 | (unless (stringp value) |
| 177 | (when-let ((bounds (haiku-selection-bounds value))) | ||
| 178 | (setq value (ignore-errors | ||
| 179 | (with-current-buffer (nth 2 bounds) | ||
| 180 | (buffer-substring (nth 0 bounds) | ||
| 181 | (nth 1 bounds))))))) | ||
| 182 | (when (and (stringp value) (not (string-empty-p value))) | ||
| 147 | (list "text/plain;charset=iso-8859-1" 1296649541 | 183 | (list "text/plain;charset=iso-8859-1" 1296649541 |
| 148 | (encode-coding-string value 'iso-latin-1)))) | 184 | (encode-coding-string value 'iso-latin-1)))) |
| 149 | 185 | ||
| @@ -151,7 +187,13 @@ under the type `text/plain;charset=iso-8859-1'." | |||
| 151 | "Convert VALUE to a system message association. | 187 | "Convert VALUE to a system message association. |
| 152 | VALUE will be encoded as UTF-8 and stored under the type | 188 | VALUE will be encoded as UTF-8 and stored under the type |
| 153 | `text/plain'." | 189 | `text/plain'." |
| 154 | (when (stringp value) | 190 | (unless (stringp value) |
| 191 | (when-let ((bounds (haiku-selection-bounds value))) | ||
| 192 | (setq value (ignore-errors | ||
| 193 | (with-current-buffer (nth 2 bounds) | ||
| 194 | (buffer-substring (nth 0 bounds) | ||
| 195 | (nth 1 bounds))))))) | ||
| 196 | (when (and (stringp value) (not (string-empty-p value))) | ||
| 155 | (list "text/plain" 1296649541 | 197 | (list "text/plain" 1296649541 |
| 156 | (encode-coding-string value 'utf-8-unix)))) | 198 | (encode-coding-string value 'utf-8-unix)))) |
| 157 | 199 | ||
| @@ -173,7 +215,7 @@ VALUE will be encoded as UTF-8 and stored under the type | |||
| 173 | (let ((result (funcall encoder type value))) | 215 | (let ((result (funcall encoder type value))) |
| 174 | (when result | 216 | (when result |
| 175 | (push result message)))) | 217 | (push result message)))) |
| 176 | (haiku-selection-put type message nil)))) | 218 | (haiku-selection-put type message)))) |
| 177 | 219 | ||
| 178 | (cl-defmethod gui-backend-selection-exists-p (selection | 220 | (cl-defmethod gui-backend-selection-exists-p (selection |
| 179 | &context (window-system haiku)) | 221 | &context (window-system haiku)) |
diff --git a/src/haikuselect.c b/src/haikuselect.c index 461482fea18..c1c619ee8c4 100644 --- a/src/haikuselect.c +++ b/src/haikuselect.c | |||
| @@ -112,7 +112,7 @@ haiku_unwind_clipboard_lock (int clipboard) | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put, | 114 | DEFUN ("haiku-selection-put", Fhaiku_selection_put, Shaiku_selection_put, |
| 115 | 3, 4, 0, | 115 | 2, 4, 0, |
| 116 | doc: /* Add or remove content from the clipboard CLIPBOARD. | 116 | doc: /* Add or remove content from the clipboard CLIPBOARD. |
| 117 | CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. NAME | 117 | CLIPBOARD is the symbol `PRIMARY', `SECONDARY' or `CLIPBOARD'. NAME |
| 118 | is a MIME type denoting the type of the data to add. DATA is the | 118 | is a MIME type denoting the type of the data to add. DATA is the |