]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/company-math/company-math.el
Merge company-math
[gnu-emacs-elpa] / packages / company-math / company-math.el
index dc8151f7937993aa335c2a01388e16480c3078f6..49d3028374ede21e11a48ee8b510371fd8a167d1 100644 (file)
@@ -4,7 +4,7 @@
 ;; Author: Vitalie Spinu <spinuvit@gmail.com>
 ;; URL: https://github.com/vspinu/company-math
 ;; Keywords:  Unicode, symbols, completion
-;; Version: 1.0.1
+;; Version: 1.1
 ;; Package-Requires: ((company "0.8.0") (math-symbol-lists "1.0"))
 ;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -54,15 +54,15 @@ When set to special value t, allow on all faces except those in
 `company-math-disallow-unicode-symbols-in-faces'."
   :group 'company-math
   :type '(choice (const t)
-                (repeat :tag "Faces" symbol)))
+                 (repeat :tag "Faces" symbol)))
 
-(defcustom company-math-allow-latex-symbols-in-faces '(font-latex-math-face)
+(defcustom company-math-allow-latex-symbols-in-faces '(tex-math font-latex-math-face)
   "List of faces to disallow the insertion of latex mathematical symbols.
 When set to special value t, allow on all faces except those in
 `company-math-disallow-latex-symbols-in-faces'."
   :group 'company-math
   :type '(choice (const t)
-                (repeat :tag "Faces" symbol)))
+                 (repeat :tag "Faces" symbol)))
 
 (defcustom company-math-disallow-unicode-symbols-in-faces '(font-latex-math-face)
   "List of faces to disallow the insertion of Unicode symbols."
@@ -85,10 +85,10 @@ corresponding unicode symbol."
   (delq nil
         (mapcar
          #'(lambda (el)
-            (let* ((tex (substring (nth 1 el) 1))
-                   (ch (and (nth 2 el) (decode-char 'ucs (nth 2 el))))
-                   (symb (and ch (char-to-string ch))))
-              (propertize tex :symbol symb)))
+             (let* ((tex (substring (nth 1 el) 1))
+                    (ch (and (nth 2 el) (decode-char 'ucs (nth 2 el))))
+                    (symb (and ch (char-to-string ch))))
+               (propertize tex :symbol symb)))
          alist)))
 
 (defconst company-math--symbols
@@ -99,19 +99,19 @@ corresponding unicode symbol."
 
 (defun company-math--prefix (allow-faces disallow-faces)
   (let* ((face (get-text-property (point) 'face))
-        (face (or (car-safe face) face))
-        (insertp (and (not (memq face disallow-faces))
-                      (or (eq t allow-faces)
-                          (memq face allow-faces)))))
+         (face (or (car-safe face) face))
+         (insertp (and (not (memq face disallow-faces))
+                       (or (eq t allow-faces)
+                           (memq face allow-faces)))))
     (when insertp
       (save-excursion
-       (when (looking-back company-math-prefix-regexp (point-at-bol))
-         (match-string 1))))))
+        (when (looking-back company-math-prefix-regexp (point-at-bol))
+          (match-string 1))))))
 
 (defun company-math--substitute-unicode (symbol)
   "Substitute preceding latex command with with SYMBOL."
   (let ((pos (point))
-       (inhibit-point-motion-hooks t))
+        (inhibit-point-motion-hooks t))
     (when (re-search-backward company-math-prefix-regexp)
       (delete-region (match-beginning 0) pos)
       (insert symbol))))
@@ -126,7 +126,7 @@ corresponding unicode symbol."
   (cl-case command
     (interactive (company-begin-backend 'company-latex-commands))
     (prefix (unless (company-in-string-or-comment)
-             (company-math--prefix t '())))
+              (company-math--prefix t '())))
     (candidates (all-completions arg math-symbol-list-latex-commands))
     (sorted t)))
 
@@ -137,25 +137,33 @@ corresponding unicode symbol."
   (cl-case command
     (interactive (company-begin-backend 'company-math-symbols-latex))
     (prefix (unless (company-in-string-or-comment)
-             (company-math--prefix company-math-allow-latex-symbols-in-faces
-                                   company-math-disallow-latex-symbols-in-faces)))
+              (company-math--prefix company-math-allow-latex-symbols-in-faces
+                                    company-math-disallow-latex-symbols-in-faces)))
     (annotation (concat " " (get-text-property 0 :symbol arg)))
     (candidates (all-completions arg company-math--symbols))))
 
 ;;;###autoload
 (defun company-math-symbols-unicode (command &optional arg &rest ignored)
-  "Company backend for LaTeX mathematical symbols."
+  "Company backend for insertion of Unicode mathematical symbols.
+See the unicode-math page [1] for a list of fonts that have a
+good support for mathematical symbols.
+
+ [1] http://ftp.snt.utwente.nl/pub/software/tex/help/Catalogue/entries/unicode-math.html
+"
   (interactive (list 'interactive))
   (cl-case command
     (interactive (company-begin-backend 'company-math-symbols-unicode))
     (prefix (company-math--prefix company-math-allow-unicode-symbols-in-faces
-                                 company-math-disallow-unicode-symbols-in-faces))
+                                  company-math-disallow-unicode-symbols-in-faces))
     (annotation (concat " " (get-text-property 0 :symbol arg)))
-    (candidates (all-completions arg company-math--symbols))
+    ;; Space added to ensure that completions are never typed in full.
+    ;; See https://github.com/company-mode/company-mode/issues/476
+    (candidates (mapcar (lambda (candidate)
+                          (concat candidate " "))
+                        (all-completions arg company-math--symbols)))
     (post-completion (company-math--substitute-unicode
-                     (get-text-property 0 :symbol arg)))))
+                      (get-text-property 0 :symbol arg)))))
 
 
 (provide 'company-math)
-
 ;;; company-math.el ends here