Skip to content

Instantly share code, notes, and snippets.

@takaxp
Last active November 3, 2016 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaxp/fc5ae440b3279679dc854e5b9adbfe08 to your computer and use it in GitHub Desktop.
Save takaxp/fc5ae440b3279679dc854e5b9adbfe08 to your computer and use it in GitHub Desktop.
Additional EMP patch to enhance usability
*** src/lisp/term/mac-win.el 2016-09-18 14:57:55.000000000 +0900
--- dst/lisp/term/mac-win.el 2016-09-23 20:49:12.000000000 +0900
***************
*** 1543,1629 ****
(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\\>"
--- 1543,1649 ----
(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\\>"
***************
*** 1651,1656 ****
--- 1671,1678 ----
(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")))
***************
*** 1691,1697 ****
(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.
***************
*** 1708,1723 ****
:type 'hook
:group 'mac)
(defun mac-text-input-handle-notification (event)
(interactive "e")
(let ((ae (mac-event-ae event)))
(let ((name (cdr (mac-ae-parameter ae 'name))))
(cond ((string= name (concat "com.apple.Carbon.TISNotify"
! "SelectedKeyboardInputSourceChanged"))
! (run-hooks 'mac-selected-keyboard-input-source-change-hook))
! ((string= name (concat "com.apple.Carbon.TISNotify"
! "EnabledKeyboardInputSourcesChanged"))
! (run-hooks 'mac-enabled-keyboard-input-sources-change-hook))))))
(define-key mac-apple-event-map [text-input set-marked-text]
'mac-text-input-set-marked-text)
--- 1731,1752 ----
:type 'hook
:group 'mac)
+ (defcustom mac-auto-ascii-setup-input-source-before-hook nil
+ "Hook that is run before automatic change to ascii."
+ :package-version '(Mac\ port . "6.0")
+ :type 'hook
+ :group 'mac)
+
(defun mac-text-input-handle-notification (event)
(interactive "e")
(let ((ae (mac-event-ae event)))
(let ((name (cdr (mac-ae-parameter ae 'name))))
(cond ((string= name (concat "com.apple.Carbon.TISNotify"
! "SelectedKeyboardInputSourceChanged"))
! (run-hooks 'mac-selected-keyboard-input-source-change-hook))
! ((string= name (concat "com.apple.Carbon.TISNotify"
! "EnabledKeyboardInputSourcesChanged"))
! (run-hooks 'mac-enabled-keyboard-input-sources-change-hook))))))
(define-key mac-apple-event-map [text-input set-marked-text]
'mac-text-input-set-marked-text)
***************
*** 1736,1741 ****
--- 1765,1771 ----
"Set up the most-recently-used ASCII-capable keyboard input source.
Expects to be bound to global keymap's prefix keys in
`input-decode-map'."
+ (run-hooks 'mac-auto-ascii-setup-input-source-before-hook)
(mac-auto-ascii-select-input-source)
(vector last-input-event))
***************
*** 1774,1789 ****
esc-map)
(add-hook 'minibuffer-setup-hook 'mac-auto-ascii-select-input-source))
(map-keymap (lambda (event definition)
! (if (eq definition 'mac-auto-ascii-setup-input-source)
! (define-key input-decode-map (vector event) nil)))
! input-decode-map)
(let ((input-decode-esc-map (lookup-key input-decode-map "\e")))
(if (keymapp input-decode-esc-map)
! (map-keymap
! (lambda (event definition)
! (if (eq definition 'mac-auto-ascii-setup-input-source)
! (define-key input-decode-map (vector ?\e event) nil)))
! input-decode-esc-map)))
(remove-hook 'minibuffer-setup-hook 'mac-auto-ascii-select-input-source)))
;;; Converted Actions
--- 1804,1819 ----
esc-map)
(add-hook 'minibuffer-setup-hook 'mac-auto-ascii-select-input-source))
(map-keymap (lambda (event definition)
! (if (eq definition 'mac-auto-ascii-setup-input-source)
! (define-key input-decode-map (vector event) nil)))
! input-decode-map)
(let ((input-decode-esc-map (lookup-key input-decode-map "\e")))
(if (keymapp input-decode-esc-map)
! (map-keymap
! (lambda (event definition)
! (if (eq definition 'mac-auto-ascii-setup-input-source)
! (define-key input-decode-map (vector ?\e event) nil)))
! input-decode-esc-map)))
(remove-hook 'minibuffer-setup-hook 'mac-auto-ascii-select-input-source)))
;;; Converted Actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment