[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7999062 01/34: Add initial stuff
From: |
Vitalie Spinu |
Subject: |
[elpa] master 7999062 01/34: Add initial stuff |
Date: |
Tue, 7 May 2019 16:05:24 -0400 (EDT) |
branch: master
commit 7999062bf64e86c8d516b894b317c43d246dec96
Author: Vitalie Spinu <address@hidden>
Commit: Vitalie Spinu <address@hidden>
Add initial stuff
---
company-math.el | 155 ++++++++++++++++++++++++++++++++++++++++++++++++
img/latex-symbols.png | Bin 0 -> 3355 bytes
img/unicode-symbols.png | Bin 0 -> 3333 bytes
readme.md | 59 ++++++++++++++++++
4 files changed, 214 insertions(+)
diff --git a/company-math.el b/company-math.el
new file mode 100644
index 0000000..390da35
--- /dev/null
+++ b/company-math.el
@@ -0,0 +1,155 @@
+;;; company-math.el --- Completion back-ends for for math unicode symbols and
latex tags
+;;
+;; Copyright (C) 2014, Vitalie Spinu
+;; Author: Vitalie Spinu
+;; URL: https://github.com/vspinu/company-math
+;; Keywords: Unicode, symbols, completion
+;; Version: 1.0
+;; Package-Requires: ((company "0.8.0") (symbols "1.0"))
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; This file is *NOT* part of GNU Emacs.
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+;; Floor, Boston, MA 02110-1301, USA.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Code:
+
+(require 'symbols)
+(require 'company)
+
+(defgroup company-math nil
+ "Completion back-ends for math symbols Unicode symbols and LaTeX tags."
+ :group 'company
+ :prefix "company-math-")
+
+(defcustom company-math-prefix-regexp "\\\\\\([^ \t]+\\)"
+ "Regexp matching the prefix of the company-math symbol.
+First subgroup must match the actual symbol to be used in the
+completion."
+ :group 'company-math)
+
+(defcustom company-math-allow-unicode-symbols-in-faces t
+ "List of faces to allow the insertion of Unicode symbols.
+Can be t if to allow on all faces except those listed in
+`company-math-disallow-unicode-symbols-in-faces'."
+ :group 'company-math
+ :type '(repeat symbol))
+
+(defcustom company-math-allow-latex-symbols-in-faces '(font-latex-math-face)
+ "List of faces to disallow the insertion of latex mathematical symbols.
+Can be t if to allow on all faces except those listed in
+`company-math-disallow-latex-symbols-in-faces'."
+ :group 'company-math
+ :type '(repeat symbol))
+
+(defcustom company-math-disallow-unicode-symbols-in-faces
'(font-latex-math-face)
+ "List of faces to disallow the insertion of Unicode symbols."
+ :group 'company-math
+ :type '(repeat symbol))
+
+(defcustom company-math-disallow-latex-symbols-in-faces '()
+ "List of faces to disallow the insertion of latex mathematical symbols."
+ :group 'company-math
+ :type '(repeat symbol))
+
+
+;;; INTERNALS
+
+(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
+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)))
+ alist)))
+
+(defconst company-math--symbols
+ (delete-dups
+ (append (company-math--make-candidates symbols-math-basic)
+ (company-math--make-candidates symbols-math-extended)))
+ "List of math completion candidates.")
+
+(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)))))
+ (when insertp
+ (save-excursion
+ (when (re-search-backward company-math-prefix-regexp (point-at-bol)
'no-error)
+ (match-string 1))))))
+
+(defun company-math--substitute-unicode (symbol)
+ "Substitute preceding latex command with with SYMBOL."
+ (let ((pos (point))
+ (inhibit-point-motion-hooks t))
+ (when (re-search-backward company-math-prefix-regexp)
+ (delete-region (match-beginning 0) pos)
+ (insert symbol))))
+
+
+;;; BACKENDS
+
+;;;###autoload
+(defun company-latex-commands (command &optional arg &rest ignored)
+ "Company backend for latex commands."
+ (interactive (list 'interactive))
+ (case command
+ (interactive (company-begin-backend 'company-latex-commands))
+ (prefix (unless (company-in-string-or-comment)
+ (company-math--prefix t '())))
+ (candidates (all-completions arg symbols-latex-commands))
+ (sorted t)))
+
+;;;###autoload
+(defun company-math-symbols-latex (command &optional arg &rest ignored)
+ "Company backend for LaTeX mathematical symbols."
+ (interactive (list 'interactive))
+ (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)))
+ (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."
+ (interactive (list 'interactive))
+ (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))
+ (annotation (concat " " (get-text-property 0 :symbol arg)))
+ (candidates (all-completions arg company-math--symbols))
+ (post-completion (company-math--substitute-unicode
+ (get-text-property 0 :symbol arg)))))
+
+
+(provide 'company-math)
+
+;;; company-math.el ends here
diff --git a/img/latex-symbols.png b/img/latex-symbols.png
new file mode 100644
index 0000000..781a46a
Binary files /dev/null and b/img/latex-symbols.png differ
diff --git a/img/unicode-symbols.png b/img/unicode-symbols.png
new file mode 100644
index 0000000..050e6fe
Binary files /dev/null and b/img/unicode-symbols.png differ
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..1e1a70e
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,59 @@
+This add-on defines three *[company-mode](https://github.com/company-mode)*
backends:
+
+ * company-math-symbols-latex - math latex tags (_by default, active only on
latex math faces_)
+
+
![symbols](https://raw.github.com/vspinu/company-math/master/img/latex-symbols.png)
+
+ * company-math-symbols-unicode - unicode symbols (_by default, active
everywhere except math faces_)
+
+
![math](https://raw.github.com/vspinu/company-math/master/img/unicode-math.png)
+
+ * company-latex-commands - latex commands
+
+## Usage ##
+
+Start math completion by typing the prefix "\" key. Select the completion type
+RET. Depending on the context and your configuration of the backends unicode
+symbol or latex \tag will be inserted.
+
+## Activation ##
+
+Install from [MELPA](http://melpa.milkbox.net/) repository.
+
+You can either register each backend globally or locally per each mode.
+
+
+```lisp
+
+;; add completions of unicode symbols globally
+(add-to-list 'company-backend 'company-math-symbols-unicode)
+
+
+```
+
+```lisp
+
+;; local configuration for TeX modes
+(defun my-latex-mode-setup ()
+ (setq-local company-backends
+ (append '(company-math-symbols-latex
+ company-latex-commands)
+ company-backends)))
+
+(add-hook 'TeX-mode-hook 'my-latex-mode-setup)
+
+
+```
+
+## Customization ##
+
+Set `company-tooltip-align-annotations` to t in order to allin symbols to the
right as in the above previews.
+
+By default unicode symbols (`company-math-math-unicode`) is not activate in
+latex math environments and latex math symbols are not available outside of
math
+latex environmnts. You can use the following variables to adjust this behavior
+to your liking: `company-math-disallow-unicode-symbols-in-faces`,
+`company-math-allow-unicode-symbols-in-faces`,
+`company-math-disallow-latex-symbols-in-faces`,
+`company-math-allow-latex-symbols-in-faces`.
+
- [elpa] master updated (86df5e9 -> 26bf67b), Vitalie Spinu, 2019/05/07
- [elpa] master b83eb6d 04/34: Readme, Vitalie Spinu, 2019/05/07
- [elpa] master 389cebc 06/34: Looks back instead of re-search-backward, Vitalie Spinu, 2019/05/07
- [elpa] master 9c5fe4c 05/34: Readme, Vitalie Spinu, 2019/05/07
- [elpa] master c970a21 03/34: Adjust to `math-symbol-lists` name change, Vitalie Spinu, 2019/05/07
- [elpa] master 9a960df 02/34: Readme, Vitalie Spinu, 2019/05/07
- [elpa] master 7999062 01/34: Add initial stuff,
Vitalie Spinu <=
- [elpa] master f5cedcf 12/34: Use generic `tex-mode-hook` in readme, Vitalie Spinu, 2019/05/07
- [elpa] master 8190924 07/34: [#1] Fix typo in readme, Vitalie Spinu, 2019/05/07
- [elpa] master e82c91d 10/34: Bump version, Vitalie Spinu, 2019/05/07
- [elpa] master 8e64cae 17/34: Untabify and add .dir-locals, Vitalie Spinu, 2019/05/07
- [elpa] master 55f0a03 08/34: require cl-lib, Vitalie Spinu, 2019/05/07
- [elpa] master 9407824 21/34: Company doesn't like nils, remove those, Vitalie Spinu, 2019/05/07
- [elpa] master 96e55e6 20/34: [Fix #8] Don't propose Unicode completions if no Ucode, Vitalie Spinu, 2019/05/07
- [elpa] master 3c906cd 15/34: Always offer completions (workaround for company issue #476), Vitalie Spinu, 2019/05/07
- [elpa] master d0db15e 13/34: [Fix #6] Add `tex-math` to `company-math-allow-latex-symbols-in-faces`, Vitalie Spinu, 2019/05/07
- [elpa] master 26bf67b 34/34: [company-math] Merge from upstream, Vitalie Spinu, 2019/05/07