]> code.delx.au - gnu-emacs-elpa/commitdiff
Merge company-math
authorVitalie Spinu <spinuvit@gmail.com>
Sun, 28 Feb 2016 14:56:45 +0000 (15:56 +0100)
committerVitalie Spinu <spinuvit@gmail.com>
Sun, 28 Feb 2016 14:56:45 +0000 (15:56 +0100)
1  2 
packages/company-math/.dir-locals.el
packages/company-math/company-math.el
packages/company-math/readme.md

index 0000000000000000000000000000000000000000,064a938a43cbb8c365ffd01ea99ab1f85d4b782b..064a938a43cbb8c365ffd01ea99ab1f85d4b782b
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,3 +1,3 @@@
+ ((emacs-lisp-mode
+   (indent-tabs-mode)))
index dc8151f7937993aa335c2a01388e16480c3078f6,383b4de5df63f5dc917780ea1752218c4d8ab7fd..49d3028374ede21e11a48ee8b510371fd8a167d1
@@@ -1,10 -1,10 +1,10 @@@
  ;;; company-math.el --- Completion backends for unicode math symbols and latex tags
  ;;
  ;; Copyright (C) 2015 Free Software Foundation, Inc.
 -;; Author: Vitalie Spinu
 +;; 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"))
  ;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@@ -28,8 -28,6 +28,8 @@@
  ;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;
 +;;; Commentary:
 +
  ;;; Code:
  
  (require 'math-symbol-lists)
@@@ -54,15 -52,15 +54,15 @@@ When set to special value t, allow on a
  `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."
  
  (defun company-math--make-candidates (alist)
    "Build a list of math symbols ready to be used in ac source.
 -ALIST is one of the defined alist in package `symbols'. Return a
 +ALIST is one of the defined alist in package `symbols'.  Return a
  list of LaTeX symbols with text property :symbol being the
  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
  
  (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))))
    (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)))
  
    (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
index cc471942ea27f6a807f7c7b7e55068ecc8aaacb3,fa8025837520f492787ccdf984f1b5f3e8901505..fa8025837520f492787ccdf984f1b5f3e8901505
@@@ -39,13 -39,19 +39,19 @@@ or locally per emacs mode
  ;; local configuration for TeX modes
  (defun my-latex-mode-setup ()
    (setq-local company-backends
-               (append '(company-math-symbols-latex company-latex-commands)
+               (append '((company-math-symbols-latex company-latex-commands))
                        company-backends)))
  
- (add-hook 'TeX-mode-hook 'my-latex-mode-setup)
+ (add-hook 'tex-mode-hook 'my-latex-mode-setup)
   
  ```
  
+ If you are using `AUCTeX` you might need to use `TeX-mode-hook` instead:
+ ```
+ (add-hook TeX-mode-hook 'my-latex-mode-setup)
+ ```
  ## Customization ##
  
  Set `company-tooltip-align-annotations` to t in order to allin symbols to the