[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/constants 5a8e9648c4 13/19: Allow the interactive promp
From: |
ELPA Syncer |
Subject: |
[elpa] externals/constants 5a8e9648c4 13/19: Allow the interactive prompt to switch the unit system |
Date: |
Tue, 27 Aug 2024 03:58:01 -0400 (EDT) |
branch: externals/constants
commit 5a8e9648c44fef145cae3d0cc83d1870c0428235
Author: Carsten Dominik <carsten.dominik@gmail.com>
Commit: Carsten Dominik <carsten.dominik@gmail.com>
Allow the interactive prompt to switch the unit system
---
README | 15 ++++++++++++---
constants.el | 43 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/README b/README
index 675ae51ad7..6334fd301d 100644
--- a/README
+++ b/README
@@ -83,6 +83,10 @@ use completion. Press `?' during completion to display a
detailed
list of all available constants. You can scroll the Help window
with S-TAB while entering text in the minibuffer.
+If you add "si" or "cgs" to the comma-separated list of
+constant/unit names, this will switch the unit system for the
+burrent buffer and editing session.
+
CUSTOMIZATION
-------------
@@ -146,7 +150,7 @@ BUGS
complete "MGa" to "MGauss" (meaning "Mega-Gauss"). This was not
implemented because it would cause too many matches during
completion. But you can still use completion for this by separating
- the prefix from the unit with a star: After typing "M*Ga", completion
+ the prefix from the unit with a star: After typing "M*Ga", completion
will work and result in "M*Gauss". Both "MGauss" and "M*Gauss" will
result in a variable "MGauss" being defined.
- When using cgs units, be very careful with the electric constants
@@ -177,11 +181,16 @@ Bruce Ignalis, Dave Pearson, Jacques L'helgoualc'h,
Federico Beffa
CHANGES
-------
+Version 2.8
+- Allow the interactive prompt to change the unit system. That
+ change will be stored locally for the current buffer and editing
+ session.
+
Version 2.7
- Add support for Python
Version 2.5
-- Better lisp indentation (patch by Federico Beffa <beffa@ieee.org>)
+- Better Lisp indentation (patch by Federico Beffa <beffa@ieee.org>)
Version 2.3
- Add a few more constants
@@ -203,7 +212,7 @@ TO DO
- Add expression values tcl and others.
- Add calc mode?
- add these units?
- - g[u]age,
+ - g[u]age,
- (circular) mill
- ampere-turn
- add a command to get info about a certain variable. Only useful if
diff --git a/constants.el b/constants.el
index cf1505f7b4..f045320bb6 100644
--- a/constants.el
+++ b/constants.el
@@ -2,7 +2,7 @@
;; Copyright (c) 2003, 2004, 2005, 2011, 2013, 2020 Carsten Dominik
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
-;; Version: 2.7
+;; Version: 2.8
;; Keywords: programming, languages
;; URL: https://github.com/cdominik/constants-for-Emacs
@@ -110,6 +110,10 @@
;; list of all available constants. You can scroll the Help window
;; with S-TAB while entering text in the minibuffer.
;;
+;; If you add "si" or "cgs" to the comma-separated list of
+;; constant/unit names, this will switch the unit system for the
+;; burrent buffer and editing session.
+;;
;;
;; CUSTOMIZATION
;; -------------
@@ -204,6 +208,11 @@
;;
;; CHANGES
;; -------
+;; Version 2.8
+;; - Allow the interactive prompt to change the unit system. That
+;; change will be stored locally for the current buffer and editing
+;; session.
+;;
;; Version 2.7
;; - Add support for Python
;;
@@ -255,6 +264,9 @@ Legal values are `cgs' and `SI'."
(const cgs)
(const SI)))
+(defvar constants-unit-system-override nil)
+(make-variable-buffer-local 'constants-unit-system-override)
+
(defcustom constants-rename
'(("kk" . "k") ("bk" . "k")
("cc" . "c") ("cl" . "c")
@@ -747,6 +759,11 @@ When called with prefix argument UNIT-SYSTEM, the
\"other\" unit
system will be used. I.e., if your default is `SI', then a prefix arg
will switch to `cgs' and vice versa.
+You can also make \"si\" or \"cgs\" one of the members of the
+comma-separated list in NAMES. This will then set a local
+variable to select that unit system for the current buffer for
+the current editing session.
+
`constants-insert' may also be called from a Lisp program - in this
case the comma-separated list of names should be given as argument
NAMES. UNIT-SYSTEM may be nil to use the default, but also `SI' or
@@ -756,6 +773,7 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but also
`SI' or
(interactive "P")
(let* ((constants-unit-system
(cond ((and unit-system (symbolp unit-system)) unit-system)
+ (constants-unit-system-override constants-unit-system-override)
(unit-system (if (eq constants-unit-system 'SI) 'cgs 'SI))
(t constants-unit-system)))
(all-constants (append constants-user-defined constants-defaults))
@@ -773,7 +791,7 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but also
`SI' or
(funcall constants-language-function))
(assq mode constants-languages)
(assq t constants-languages)))
- format exp-string
+ format exp-string unit-system
pmatch factor name prefix-name rpl prefix-exp force-prefix
process-func
const prefix entry entry1 desc value ins beg linelist line vname)
;; Check for fentry aliasing
@@ -788,6 +806,14 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but
also `SI' or
;; extract format specifications
(setq format (nth 1 fentry) exp-string (nth 2 fentry)
prefix-exp (nth 3 fentry) process-func (nth 4 fentry))
+ ; Let's see if the unit system is
specifid in this string
+ (while (setq unit-system (or (member "si" clist) (member "cgs" clist)
+ (member "SI" clist) (member "CGS" clist)))
+ (setq unit-system (car unit-system))
+ (constants-set-unit-system unit-system)
+ (message "Setting unit system to %s" unit-system)
+ (setq clist (delete unit-system clist)))
+ ; Now process the list of units given
(while (setq const (pop clist))
(setq prefix nil factor nil prefix-name "" force-prefix nil vname nil)
(if (string-match "\\(.*\\)=\\(.*\\)" const)
@@ -918,7 +944,7 @@ bahavior also in a programmatic call."
;; FIXME: There is a lot of code duplication with constants-insert here,
;; maybe we should restructure this at some point. For now, it works.
(interactive)
- (let* ((constants-unit-system (or unit-system constants-unit-system))
+ (let* ((constants-unit-system (or unit-system constants-unit-system-override
constants-unit-system))
(all-constants (append constants-user-defined constants-defaults))
(atable (append constants-rename all-constants))
entry prefix prefix-name pmatch unit factor value ok)
@@ -994,6 +1020,14 @@ For example \"pi\" would be replaced by
\"3.1415926535897932385\"."
(replace-match value t t)
(error "No such constant: %s" (match-string 0))))))
+(defun constants-set-unit-system (system)
+ "Set unit system and make sure it persists in this buffer."
+ (if (equal (downcase system) "cgs")
+ (setq constants-unit-system 'cgs
+ constants-unit-system-override 'cgs)
+ (setq constants-unit-system 'SI
+ constants-unit-system-override 'SI)))
+
(defun constants-get-value (entry mode)
"Extract the correct value string from the ENTRY for mode MODE."
(let (ee val)
@@ -1048,7 +1082,7 @@ and follow it up."
(lambda ()
(interactive)
(let ((major-mode constants-major-mode))
- (constants-help nil 'completing))))
+ (constants-help constants-unit-system 'completing))))
(define-key minibuffer-local-completion-map [(shift tab)]
'constants-scroll-help)
(unwind-protect
(progn
@@ -1125,6 +1159,7 @@ used. I.e., if your default is `SI', then a prefix arg
will switch to
(let* ((constants-unit-system
(cond ((and unit-system (symbolp unit-system)) unit-system)
(unit-system (if (eq constants-unit-system 'SI) 'cgs 'SI))
+ (constants-unit-system-override
constants-unit-system-override)
(t constants-unit-system)))
(all (append constants-user-defined constants-defaults))
(us (symbol-name constants-unit-system))
- [elpa] externals/constants b0bf11101a 09/19: Fix bug in Makefile, (continued)
- [elpa] externals/constants b0bf11101a 09/19: Fix bug in Makefile, ELPA Syncer, 2024/08/27
- [elpa] externals/constants d123338020 04/19: Add acknowledgment to Federico Beffa, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 4ac12e8b99 08/19: Prepare for MELPA, ELPA Syncer, 2024/08/27
- [elpa] externals/constants ebd7563ec8 06/19: Add URL, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 5cf71fa5a8 11/19: Merge pull request #2 from janEbert/elisp-exponent-string, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 4d0da8e717 14/19: Some code cleanup preparing for package release., ELPA Syncer, 2024/08/27
- [elpa] externals/constants ad9999a820 12/19: Fix bug: GG should mean Grav, not gram, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 83cf062de2 01/19: Initial commit, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 5ef0047a7a 18/19: Remove unnecessary `group' assignments in defcustom forms, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 2000f311fc 10/19: Fix emacs-lisp exponent string, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 5a8e9648c4 13/19: Allow the interactive prompt to switch the unit system,
ELPA Syncer <=
- [elpa] externals/constants a885f4f752 19/19: Ready for EPLA inclusion, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 38741adc80 05/19: Update README, ELPA Syncer, 2024/08/27
- [elpa] externals/constants bac41aff7b 16/19: Make small changes to get ready for ELPA, ELPA Syncer, 2024/08/27
- [elpa] externals/constants 5454a8cd53 02/19: Initial commit, ELPA Syncer, 2024/08/27
- [elpa] externals/constants c183d1cf00 17/19: resolve conflicts, ELPA Syncer, 2024/08/27