Skip to content

Instantly share code, notes, and snippets.

@takaxp
Last active September 15, 2016 14:50
Show Gist options
  • Save takaxp/d2137e0add397440229f3b309643ec3a to your computer and use it in GitHub Desktop.
Save takaxp/d2137e0add397440229f3b309643ec3a to your computer and use it in GitHub Desktop.
my-emacs-mac.patch
*** src/lisp/term/mac-win.el 2016-09-15 23:40:56.000000000 +0900
--- dst/lisp/term/mac-win.el 2016-09-15 22:11:59.000000000 +0900
***************
*** 1542,1628 ****
(2 . mac-ts-selected-converted-text)) ; NSUnderlineStyleThick
"Alist of NSUnderlineStyle vs Emacs face in marked text.")
(defun mac-text-input-set-marked-text (event)
(interactive "e")
(let* ((ae (mac-event-ae event))
! (text (cdr (mac-ae-parameter ae)))
! (selected-range (cdr (mac-ae-parameter ae "selectedRange")))
! (replacement-range (cdr (mac-ae-parameter ae "replacementRange")))
! (script-language (mac-ae-script-language ae "tssl"))
! (coding (and script-language
! (or (cdr (assq (car script-language)
! mac-script-code-coding-systems))
! 'mac-roman))))
(let ((use-echo-area
! (or isearch-mode
! (and cursor-in-echo-area (current-message))
! ;; Overlay strings are not shown in some cases.
! (get-char-property (point) 'invisible)
! (and (not (bobp))
! (or (and (get-char-property (point) 'display)
! (eq (get-char-property (1- (point)) 'display)
! (get-char-property (point) 'display)))
! (and (get-char-property (point) 'composition)
! (eq (get-char-property (1- (point)) 'composition)
! (get-char-property (point) 'composition)))))))
! active-input-string caret-seen)
;; Decode the active input area text with inheriting faces and
;; the caret position.
(put-text-property (* (car selected-range) 2) (length text)
! 'cursor t text)
(setq active-input-string
! (mapconcat
! (lambda (str)
! (let* ((decoded (mac-utxt-to-string str coding))
! (underline-style
! (or (cdr (get-text-property 0 'NSUnderline str)) 0))
! (face
! (cdr (assq underline-style
! mac-marked-text-underline-style-faces))))
! (put-text-property 0 (length decoded) 'face face decoded)
! (when (and (not caret-seen)
! (get-text-property 0 'cursor str))
! (setq caret-seen t)
! (if (or use-echo-area (null cursor-type))
! (put-text-property 0 1 'face 'mac-ts-caret-position
! decoded)
! (put-text-property 0 1 'cursor t decoded)))
! decoded))
! (mac-split-string-by-property-change text)
! ""))
(put-text-property 0 (length active-input-string)
! 'mac-ts-active-input-string t active-input-string)
(if use-echo-area
! (let ((msg (current-message))
! message-log-max)
! (if (and msg
! ;; Don't get confused by previously displayed
! ;; `active-input-string'.
! (null (get-text-property 0 'mac-ts-active-input-string
! msg)))
! (setq msg (propertize msg 'display
! (concat msg active-input-string)))
! (setq msg active-input-string))
! (message "%s" msg)
! (move-overlay mac-ts-active-input-overlay 1 1)
! (overlay-put mac-ts-active-input-overlay 'before-string nil))
! (move-overlay mac-ts-active-input-overlay
! (point)
! (if (and delete-selection-mode transient-mark-mode
! mark-active (not buffer-read-only))
! (mark)
! (point))
! (current-buffer))
! (overlay-put mac-ts-active-input-overlay 'before-string
! active-input-string)
! (if replacement-range
! (condition-case nil
! ;; Strictly speaking, the replacement range can be out
! ;; of sync.
! (delete-region (+ (point-min) (car replacement-range))
! (+ (point-min) (car replacement-range)
! (cdr replacement-range)))
! (error nil))))
(setq mac-ts-active-input-string active-input-string))))
(defvar mac-emoji-font-regexp "\\<emoji\\>"
--- 1542,1648 ----
(2 . mac-ts-selected-converted-text)) ; NSUnderlineStyleThick
"Alist of NSUnderlineStyle vs Emacs face in marked text.")
+ (defvar mac-win-debug-log nil)
+ (defvar mac-win-ime-cursor-type nil)
+ (defvar mac-win-default-background-echo-area nil)
+ (defun mac-min--minibuffer-setup ()
+ (let ((bg (face-background 'default)))
+ (setq-local face-remapping-alist
+ `((mac-ts-converted-text :background ,bg)
+ (mac-ts-selected-converted-text :background ,bg)))))
(defun mac-text-input-set-marked-text (event)
(interactive "e")
+ (when mac-win-debug-log
+ (message "mac-text-input-set-marked-text: %s" event))
(let* ((ae (mac-event-ae event))
! (text (cdr (mac-ae-parameter ae)))
! (selected-range (cdr (mac-ae-parameter ae "selectedRange")))
! (replacement-range (cdr (mac-ae-parameter ae "replacementRange")))
! (script-language (mac-ae-script-language ae "tssl"))
! (coding (and script-language
! (or (cdr (assq (car script-language)
! mac-script-code-coding-systems))
! 'mac-roman))))
! (when mac-win-ime-cursor-type
! (if (and (= (car selected-range) 0) (> (cdr selected-range) 0))
! (setq cursor-type '(bar . 0))
! (setq cursor-type mac-win-ime-cursor-type)))
(let ((use-echo-area
! (or isearch-mode
! (and cursor-in-echo-area (current-message))
! ;; Overlay strings are not shown in some cases.
! (get-char-property (point) 'invisible)
! (and (not (bobp))
! (or (and (get-char-property (point) 'display)
! (eq (get-char-property (1- (point)) 'display)
! (get-char-property (point) 'display)))
! (and (get-char-property (point) 'composition)
! (eq (get-char-property (1- (point)) 'composition)
! (get-char-property (point) 'composition)))))))
! active-input-string caret-seen)
;; Decode the active input area text with inheriting faces and
;; the caret position.
(put-text-property (* (car selected-range) 2) (length text)
! 'cursor t text)
(setq active-input-string
! (mapconcat
! (lambda (str)
! (let* ((decoded (mac-utxt-to-string str coding))
! (underline-style
! (or (cdr (get-text-property 0 'NSUnderline str)) 0))
! (face
! (cdr (assq underline-style
! mac-marked-text-underline-style-faces))))
! (put-text-property 0 (length decoded) 'face face decoded)
! (when (and (not caret-seen)
! (get-text-property 0 'cursor str))
! (setq caret-seen t)
! (if (or use-echo-area (null cursor-type))
! (put-text-property 0 1 'face 'mac-ts-caret-position
! decoded)
! (put-text-property 0 1 'cursor t decoded)))
! decoded))
! (mac-split-string-by-property-change text)
! ""))
(put-text-property 0 (length active-input-string)
! 'mac-ts-active-input-string t active-input-string)
(if use-echo-area
! (let ((msg (current-message))
! message-log-max)
! (when mac-win-default-background-echo-area
! (put-text-property
! 0 (length active-input-string)
! 'face
! `(background-color . ,(face-background 'default))
! active-input-string))
! (if (and msg
! ;; Don't get confused by previously displayed
! ;; `active-input-string'.
! (null (get-text-property 0 'mac-ts-active-input-string
! msg)))
! (setq msg (propertize msg 'display
! (concat msg active-input-string)))
! (setq msg active-input-string))
! (message "%s" msg)
! (move-overlay mac-ts-active-input-overlay 1 1)
! (overlay-put mac-ts-active-input-overlay 'before-string nil))
! (move-overlay mac-ts-active-input-overlay
! (point)
! (if (and delete-selection-mode transient-mark-mode
! mark-active (not buffer-read-only))
! (mark)
! (point))
! (current-buffer))
! (overlay-put mac-ts-active-input-overlay 'before-string
! active-input-string)
! (if replacement-range
! (condition-case nil
! ;; Strictly speaking, the replacement range can be out
! ;; of sync.
! (delete-region (+ (point-min) (car replacement-range))
! (+ (point-min) (car replacement-range)
! (cdr replacement-range)))
! (error nil))))
(setq mac-ts-active-input-string active-input-string))))
(defvar mac-emoji-font-regexp "\\<emoji\\>"
***************
*** 1650,1655 ****
--- 1670,1677 ----
(defun mac-text-input-insert-text (event)
(interactive "e")
+ (when mac-win-debug-log
+ (message "mac-text-input-insert-text: %s" event))
(let* ((ae (mac-event-ae event))
(text (cdr (mac-ae-parameter ae)))
(replacement-range (cdr (mac-ae-parameter ae "replacementRange")))
***************
*** 1690,1696 ****
(string-match mac-emoji-font-regexp
(symbol-name (font-get font :family))))
(setq string (mac-complement-emoji-by-variation-selector string)))
! (mac-unread-string string))))
(defcustom mac-selected-keyboard-input-source-change-hook nil
"Hook run for a change to the selected keyboard input source.
--- 1712,1720 ----
(string-match mac-emoji-font-regexp
(symbol-name (font-get font :family))))
(setq string (mac-complement-emoji-by-variation-selector string)))
! (mac-unread-string string)))
! (when mac-win-ime-cursor-type
! (setq cursor-type mac-win-ime-cursor-type)))
(defcustom mac-selected-keyboard-input-source-change-hook nil
"Hook run for a change to the selected keyboard input source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment