emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/cdlatex 25e8e65acc 04/13: First full and working implement


From: ELPA Syncer
Subject: [nongnu] elpa/cdlatex 25e8e65acc 04/13: First full and working implementation.
Date: Sat, 12 Aug 2023 12:59:19 -0400 (EDT)

branch: elpa/cdlatex
commit 25e8e65acc2689dc490b2c132696af46058a59aa
Author: Carsten Dominik <dominik@sp-byods-145-109-124-208.wireless.uva.nl>
Commit: Carsten Dominik <dominik@sp-byods-145-109-124-208.wireless.uva.nl>

    First full and working implementation.
---
 electricindex.el | 48 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/electricindex.el b/electricindex.el
index 46b6d61e16..1b3e512030 100644
--- a/electricindex.el
+++ b/electricindex.el
@@ -1,9 +1,9 @@
-;;; electricindex.el --- Fast input methods for LaTeX environments and math  
-*- lexical-binding: t; -*-
-;; Copyright (c) 2010-2022  Free Software Foundation, Inc.
+;;; electricindex.el --- Fast digit index insertion -*- lexical-binding: t; -*-
+;; Copyright (c) 2022  Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
 ;; Keywords: tex
-;; Version: 4.14
+;; Version: 0.1
 ;;
 ;; This file is not part of GNU Emacs.
 ;;
@@ -24,8 +24,8 @@
 ;;
 ;;; Commentary:
 ;;
-;; Electricindex is a minor mode supporting fast insertion of environment
-;; templates and math stuff in LaTeX.
+;; Electricindex is a minor mode supporting fast digit index insertation in
+;; LaTeX math. For example typing  x 1 2  will insert x_{12}.
 ;;
 ;; To turn Electricindex Minor Mode on and off in a particular buffer, use
 ;; `M-x electricindex-mode'.
@@ -33,8 +33,11 @@
 ;; To turn on Electricindex Minor Mode for all LaTeX files, add one of the
 ;; following lines to your .emacs file:
 ;;
-;;   (add-hook 'LaTeX-mode-hook #'turn-on-electricindex)   ; with AUCTeX LaTeX 
mode
-;;   (add-hook 'latex-mode-hook #'turn-on-electricindex)   ; with Emacs latex 
mode
+;;   (add-hook 'latex-mode-hook #'turn-on-electricindex)
+;;
+;; This index insertion will only work when the cursor is in a LaTeX math
+;; environment, based on (texmathp). If texmathp is not available, math
+;; math-mode will be assumed.
 ;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
@@ -89,9 +92,7 @@
 Here is a list of features: \\<electricindex-mode-map>
 
 Entering `electricindex-mode' calls the hook electricindex-mode-hook."
-  :lighter " EI"
-  (when electricindex-mode
-    (electricindex-compute-tables)))
+  :lighter " EI")
 
 (defalias 'electricindex--texmathp
   (if (fboundp 'texmathp) #'texmathp
@@ -99,11 +100,34 @@ Entering `electricindex-mode' calls the hook 
electricindex-mode-hook."
     ;; can install AUCTeX.  Tho maybe we should move texmathp into its
     ;; own package so it can be used even when AUCTeX is not
     ;; installed/activated.
-    #'ignore))
+    t))
 
 ;;; ===========================================================================
 ;;;
-;;; Functions that check out the surroundings
+
+(defun electricindex-digit ()
+  "Insert digit, maybe as an index to a quantity in math environment."
+  (interactive)
+  (if (not (electricindex--texmathp))
+      (self-insert-command 1)
+    (let ((digit (char-to-string (event-basic-type last-command-event))))
+      (if (looking-back "[a-zA-Z]" (1- (point)))
+          (insert "_" digit " ")
+        (if (looking-back "\\(_[0-9]\\) ?" (- (point) 3))
+            (progn
+              (goto-char (match-beginning 1))
+              (forward-char 1)
+              (insert "{")
+              (forward-char 1)
+              (insert digit "}")
+              (if (looking-at "")
+                  (forward-char 1)
+                (insert "")))
+          (if (looking-back "_{\\([0-9]+\\)} ?" (max (- (point) 10) 
(point-min)))
+              (save-excursion
+                (goto-char (match-end 1))
+                (insert digit))
+            (self-insert-command 1)))))))
 
 (provide 'electricindex)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]