diff options
| -rw-r--r-- | cape.el | 123 |
1 files changed, 62 insertions, 61 deletions
@@ -589,29 +589,30 @@ If INTERACTIVE is nil the function acts like a capf." "Define quail translation variable with NAME. METHOD is the input method. PREFIX is the prefix regular expression." - (describe-input-method method) - (let ((capf (intern (format "cape-%s" name))) - (list (intern (format "cape--%s-list" name))) - (ann (intern (format "cape--%s-annotation" name))) - (docsig (intern (format "cape--%s-docsig" name))) - (exit (intern (format "cape--%s-exit" name))) - (properties (intern (format "cape--%s-properties" name))) - (translation - (with-current-buffer "*Help*" - (let ((lines - (split-string - (replace-regexp-in-string - "\n\n\\(\n\\|.\\)*" "" - (replace-regexp-in-string - "\\`\\(\n\\|.\\)*?----\n" "" + (save-window-excursion + (describe-input-method method) + (let ((capf (intern (format "cape-%s" name))) + (list (intern (format "cape--%s-list" name))) + (ann (intern (format "cape--%s-annotation" name))) + (docsig (intern (format "cape--%s-docsig" name))) + (exit (intern (format "cape--%s-exit" name))) + (properties (intern (format "cape--%s-properties" name))) + (translation + (with-current-buffer "*Help*" + (let ((lines + (split-string (replace-regexp-in-string - "\\`\\(\n\\|.\\)*?KEY SEQUENCE\n-+\n" "" - (buffer-string)))) - "\n")) - (list nil)) - (dolist (line lines) - (let ((beg 0) (len (length line))) - (while (< beg len) + "\n\n\\(\n\\|.\\)*" "" + (replace-regexp-in-string + "\\`\\(\n\\|.\\)*?----\n" "" + (replace-regexp-in-string + "\\`\\(\n\\|.\\)*?KEY SEQUENCE\n-+\n" "" + (buffer-string)))) + "\n")) + (list nil)) + (dolist (line lines) + (let ((beg 0) (len (length line))) + (while (< beg len) (let* ((ename (next-single-property-change beg 'face line len)) (echar (next-single-property-change ename 'face line len))) (when (and (get-text-property beg 'face line) (< ename len) (<= echar len)) @@ -620,49 +621,49 @@ PREFIX is the prefix regular expression." (when (= (length char) 1) (push (cons name (aref char 0)) list)))) (setq beg echar))))) - (kill-buffer-and-window) - (sort list (lambda (x y) (string< (car x) (car y)))))))) - `(progn - (defvar ,list ',translation) - (defun ,ann (name) - (when-let (char (cdr (assoc name ,list))) - (format " %c" char))) - (defun ,docsig (name) - (when-let (char (cdr (assoc name ,list))) - (format "%s (%s)" - (get-char-code-property char 'name) - (char-code-property-description - 'general-category - (get-char-code-property char 'general-category))))) - (defun ,exit (name status) - (unless (eq status 'exact) + (kill-buffer) + (sort list (lambda (x y) (string< (car x) (car y)))))))) + `(progn + (defvar ,list ',translation) + (defun ,ann (name) (when-let (char (cdr (assoc name ,list))) - (delete-region (max (point-min) (- (point) (length name))) (point)) - (insert (char-to-string char))))) - (defvar ,properties - (list :annotation-function #',ann - :company-docsig #',docsig - :exit-function #',exit - :company-kind (lambda (_) 'text))) - (defun ,capf (&optional interactive) - ,(format "Complete unicode character at point. + (format " %c" char))) + (defun ,docsig (name) + (when-let (char (cdr (assoc name ,list))) + (format "%s (%s)" + (get-char-code-property char 'name) + (char-code-property-description + 'general-category + (get-char-code-property char 'general-category))))) + (defun ,exit (name status) + (unless (eq status 'exact) + (when-let (char (cdr (assoc name ,list))) + (delete-region (max (point-min) (- (point) (length name))) (point)) + (insert (char-to-string char))))) + (defvar ,properties + (list :annotation-function #',ann + :company-docsig #',docsig + :exit-function #',exit + :company-kind (lambda (_) 'text))) + (defun ,capf (&optional interactive) + ,(format "Complete unicode character at point. Uses the same input format as the %s input method, see `describe-input-method'. If INTERACTIVE is nil the function acts like a capf." method) - (interactive (list t)) - (if interactive - ;; NOTE: Disable cycling since replacement breaks it. - (let (completion-cycle-threshold) - (cape--interactive #',capf)) - (require 'thingatpt) - (let ((bounds (if (thing-at-point-looking-at ,(format "%s[^ \n\t]*" prefix)) - (cons (match-beginning 0) (match-end 0)) - (cons (point) (point))))) - (append - (list (car bounds) (cdr bounds) - (cape--table-with-properties ,list :category ',capf) - :exclusive 'no) - ,properties))))))) + (interactive (list t)) + (if interactive + ;; NOTE: Disable cycling since replacement breaks it. + (let (completion-cycle-threshold) + (cape--interactive #',capf)) + (require 'thingatpt) + (let ((bounds (if (thing-at-point-looking-at ,(format "%s[^ \n\t]*" prefix)) + (cons (match-beginning 0) (match-end 0)) + (cons (point) (point))))) + (append + (list (car bounds) (cdr bounds) + (cape--table-with-properties ,list :category ',capf) + :exclusive 'no) + ,properties)))))))) ;;;###autoload (autoload 'cape-tex "cape" nil t) ;;;###autoload (autoload 'cape-sgml "cape" nil t) |
