243 |
x-invocation-args (cdr x-invocation-args))) |
x-invocation-args (cdr x-invocation-args))) |
244 |
|
|
245 |
(defvar emacs-save-session-functions nil |
(defvar emacs-save-session-functions nil |
246 |
"Functions to run when a save-session event occurs. |
"Special hook run when a save-session event occurs. |
247 |
The functions does not get any argument. |
The functions do not get any argument. |
248 |
Functions can return non-nil to inform the session manager that the |
Functions can return non-nil to inform the session manager that the |
249 |
window system shutdown should be aborted. |
window system shutdown should be aborted. |
250 |
|
|
1159 |
|
|
1160 |
;;;; Function keys |
;;;; Function keys |
1161 |
|
|
|
(defun iconify-or-deiconify-frame () |
|
|
"Iconify the selected frame, or deiconify if it's currently an icon." |
|
|
(interactive) |
|
|
(if (eq (cdr (assq 'visibility (frame-parameters))) t) |
|
|
(iconify-frame) |
|
|
(make-frame-visible))) |
|
|
|
|
1162 |
(substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame |
(substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame |
1163 |
global-map) |
global-map) |
1164 |
|
|
2138 |
(setq x-last-selected-text-clipboard text)) |
(setq x-last-selected-text-clipboard text)) |
2139 |
) |
) |
2140 |
|
|
2141 |
|
(defvar x-select-request-type nil |
2142 |
|
"*Data type request for X selection. |
2143 |
|
The value is nil, one of the following data types, or a list of them: |
2144 |
|
`COMPOUND_TEXT', `UTF8_STRING', `STRING', `TEXT' |
2145 |
|
|
2146 |
|
If the value is nil, try `COMPOUND_TEXT' and `UTF8_STRING', and |
2147 |
|
use the more appropriate result. If both fail, try `STRING', and |
2148 |
|
then `TEXT'. |
2149 |
|
|
2150 |
|
If the value is one of the above symbols, try only the specified |
2151 |
|
type. |
2152 |
|
|
2153 |
|
If the value is a list of them, try each of them in the specified |
2154 |
|
order until succeed.") |
2155 |
|
|
2156 |
|
;; Helper function for x-selection-value. Select UTF8 or CTEXT |
2157 |
|
;; whichever is more appropriate. Here, we use this heurisitcs. |
2158 |
|
;; |
2159 |
|
;; (1) If their lengthes are different, select the longer one. This |
2160 |
|
;; is because an X client may just cut off unsupported characters. |
2161 |
|
;; |
2162 |
|
;; (2) Otherwise, if the Nth character of CTEXT is an ASCII |
2163 |
|
;; character that is different from the Nth character of UTF8, |
2164 |
|
;; select UTF8. This is because an X client may replace unsupported |
2165 |
|
;; characters with some ASCII character (typically ` ' or `?') in |
2166 |
|
;; CTEXT. |
2167 |
|
;; |
2168 |
|
;; (3) Otherwise, select CTEXT. This is because legacy charsets are |
2169 |
|
;; better for the current Emacs, especially when the selection owner |
2170 |
|
;; is also Emacs. |
2171 |
|
|
2172 |
|
(defun x-select-utf8-or-ctext (utf8 ctext) |
2173 |
|
(let ((len-utf8 (length utf8)) |
2174 |
|
(len-ctext (length ctext)) |
2175 |
|
(selected ctext) |
2176 |
|
(i 0) |
2177 |
|
char) |
2178 |
|
(if (/= len-utf8 len-ctext) |
2179 |
|
(if (> len-utf8 len-ctext) utf8 ctext) |
2180 |
|
(while (< i len-utf8) |
2181 |
|
(setq char (aref ctext i)) |
2182 |
|
(if (and (< char 128) (/= char (aref utf8 i))) |
2183 |
|
(setq selected utf8 |
2184 |
|
i len-utf8) |
2185 |
|
(setq i (1+ i)))) |
2186 |
|
selected))) |
2187 |
|
|
2188 |
|
(defun x-selection-value (type) |
2189 |
|
(let (text) |
2190 |
|
(cond ((null x-select-request-type) |
2191 |
|
(let (utf8 ctext utf8-coding) |
2192 |
|
;; We try both UTF8_STRING and COMPOUND_TEXT, and choose |
2193 |
|
;; the more appropriate one. If both fail, try STRING. |
2194 |
|
|
2195 |
|
;; At first try UTF8_STRING. |
2196 |
|
(setq utf8 (condition-case nil |
2197 |
|
(x-get-selection type 'UTF8_STRING) |
2198 |
|
(error nil)) |
2199 |
|
utf8-coding last-coding-system-used) |
2200 |
|
(if utf8 |
2201 |
|
;; If it is a locale selection, choose it. |
2202 |
|
(or (get-text-property 0 'foreign-selection utf8) |
2203 |
|
(setq text utf8))) |
2204 |
|
;; If not yet decided, try COMPOUND_TEXT. |
2205 |
|
(if (not text) |
2206 |
|
(if (setq ctext (condition-case nil |
2207 |
|
(x-get-selection type 'COMPOUND_TEXT) |
2208 |
|
(error nil))) |
2209 |
|
;; If UTF8_STRING was also successful, choose the |
2210 |
|
;; more appropriate one from UTF8 and CTEXT. |
2211 |
|
(if utf8 |
2212 |
|
(setq text (x-select-utf8-or-ctext utf8 ctext)) |
2213 |
|
;; Othewise, choose CTEXT. |
2214 |
|
(setq text ctext)))) |
2215 |
|
;; If not yet decided, try STRING. |
2216 |
|
(or text |
2217 |
|
(setq text (condition-case nil |
2218 |
|
(x-get-selection type 'STRING) |
2219 |
|
(error nil)))) |
2220 |
|
(if (eq text utf8) |
2221 |
|
(setq last-coding-system-used utf8-coding)))) |
2222 |
|
|
2223 |
|
((consp x-select-request-type) |
2224 |
|
(let ((tail x-select-request-type)) |
2225 |
|
(while (and tail (not text)) |
2226 |
|
(condition-case nil |
2227 |
|
(setq text (x-get-selection type (car tail))) |
2228 |
|
(error nil)) |
2229 |
|
(setq tail (cdr tail))))) |
2230 |
|
|
2231 |
|
(t |
2232 |
|
(condition-case nil |
2233 |
|
(setq text (x-get-selection type x-select-request-type)) |
2234 |
|
(error nil)))) |
2235 |
|
|
2236 |
|
(if text |
2237 |
|
(remove-text-properties 0 (length text) '(foreign-selection nil) text)) |
2238 |
|
text)) |
2239 |
|
|
2240 |
;;; Return the value of the current X selection. |
;;; Return the value of the current X selection. |
2241 |
;;; Consult the selection, and the cut buffer. Treat empty strings |
;;; Consult the selection, and the cut buffer. Treat empty strings |
2242 |
;;; as if they were unset. |
;;; as if they were unset. |
2246 |
(defun x-cut-buffer-or-selection-value () |
(defun x-cut-buffer-or-selection-value () |
2247 |
(let (clip-text primary-text cut-text) |
(let (clip-text primary-text cut-text) |
2248 |
(when x-select-enable-clipboard |
(when x-select-enable-clipboard |
2249 |
;; Don't die if x-get-selection signals an error. |
(setq clip-text (x-selection-value 'CLIPBOARD)) |
|
(if (null clip-text) |
|
|
(condition-case c |
|
|
(setq clip-text (x-get-selection 'CLIPBOARD 'COMPOUND_TEXT)) |
|
|
(error nil))) |
|
|
(if (null clip-text) |
|
|
(condition-case c |
|
|
(setq clip-text (x-get-selection 'CLIPBOARD 'STRING)) |
|
|
(error nil))) |
|
2250 |
(if (string= clip-text "") (setq clip-text nil)) |
(if (string= clip-text "") (setq clip-text nil)) |
2251 |
|
|
2252 |
;; Check the CLIPBOARD selection for 'newness', is it different |
;; Check the CLIPBOARD selection for 'newness', is it different |
2266 |
(setq x-last-selected-text-clipboard clip-text)))) |
(setq x-last-selected-text-clipboard clip-text)))) |
2267 |
) |
) |
2268 |
|
|
2269 |
;; Don't die if x-get-selection signals an error. |
(setq primary-text (x-selection-value 'PRIMARY)) |
|
(if (null primary-text) |
|
|
(condition-case c |
|
|
(setq primary-text (x-get-selection 'PRIMARY 'COMPOUND_TEXT)) |
|
|
(error nil))) |
|
|
(if (null primary-text) |
|
|
(condition-case c |
|
|
(setq primary-text (x-get-selection 'PRIMARY 'STRING)) |
|
|
(error nil))) |
|
2270 |
;; Check the PRIMARY selection for 'newness', is it different |
;; Check the PRIMARY selection for 'newness', is it different |
2271 |
;; from what we remebered them to be last time we did a |
;; from what we remebered them to be last time we did a |
2272 |
;; cut/paste operation. |
;; cut/paste operation. |
2301 |
(t |
(t |
2302 |
(setq x-last-selected-text-cut cut-text)))) |
(setq x-last-selected-text-cut cut-text)))) |
2303 |
|
|
2304 |
|
;; As we have done one selection, clear this now. |
2305 |
|
(setq next-selection-coding-system nil) |
2306 |
|
|
2307 |
;; At this point we have recorded the current values for the |
;; At this point we have recorded the current values for the |
2308 |
;; selection from clipboard (if we are supposed to) primary, |
;; selection from clipboard (if we are supposed to) primary, |
2309 |
;; and cut buffer. So return the first one that has changed |
;; and cut buffer. So return the first one that has changed |
2446 |
;; Don't show the frame name; that's redundant with X. |
;; Don't show the frame name; that's redundant with X. |
2447 |
(setq-default mode-line-frame-identification " ") |
(setq-default mode-line-frame-identification " ") |
2448 |
|
|
2449 |
;;; Motif direct handling of f10 wasn't working right, |
;; Motif direct handling of f10 wasn't working right, |
2450 |
;;; So temporarily we've turned it off in lwlib-Xm.c |
;; So temporarily we've turned it off in lwlib-Xm.c |
2451 |
;;; and turned the Emacs f10 back on. |
;; and turned the Emacs f10 back on. |
2452 |
;;; ;; Motif normally handles f10 itself, so don't try to handle it a second time. |
;; ;; Motif normally handles f10 itself, so don't try to handle it a second time. |
2453 |
;;; (if (featurep 'motif) |
;; (if (featurep 'motif) |
2454 |
;;; (global-set-key [f10] 'ignore)) |
;; (global-set-key [f10] 'ignore)) |
2455 |
|
|
2456 |
|
;; Turn on support for mouse wheels. |
2457 |
|
(mouse-wheel-mode 1) |
2458 |
|
|
2459 |
|
;;; arch-tag: f1501302-db8b-4d95-88e3-116697d89f78 |
2460 |
;;; x-win.el ends here |
;;; x-win.el ends here |