* Re: Submission new elpa package constants-for-Emacs by Carsten Dominik
2024-08-08 8:11 Submission new elpa package constants-for-Emacs by Carsten Dominik Carsten Dominik
2024-08-11 6:56 ` Eshel Yaron
@ 2024-08-12 10:57 ` Philip Kaludercic
1 sibling, 0 replies; 3+ messages in thread
From: Philip Kaludercic @ 2024-08-12 10:57 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-devel, Ihor Radchenko
[-- Attachment #1: Type: text/plain, Size: 1546 bytes --]
Carsten Dominik <carsten.dominik@gmail.com> writes:
> Dear Emacs team,
>
> I would like to submit the attached patch to add my constants.el file as a
> package "constants-for-Emacs" to ELPA. The file is hosted at
> https://github.com/cdominik/constants-for-Emacs.
>
> Thanks to Ihor Radchenko for triggering me to submit the package and
> for providing the patch
>
> Kind regards
>
> Carsten Dominik
> From 20474fe5d48d94e2efe50fea6df4744d80051ea9 Mon Sep 17 00:00:00 2001
> Message-ID: <20474fe5d48d94e2efe50fea6df4744d80051ea9.1723103048.git.yantar92@posteo.net>
> From: Ihor Radchenko <yantar92@posteo.net>
> Date: Thu, 8 Aug 2024 09:43:52 +0200
> Subject: [PATCH] * elpa-packages (constants): New package
>
> ---
> elpa-packages | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/elpa-packages b/elpa-packages
> index 4cae4219d..cd6dec997 100644
> --- a/elpa-packages
> +++ b/elpa-packages
> @@ -168,6 +168,8 @@
> (company-statistics :url "https://github.com/company-mode/company-statistics")
> (compat :url "https://github.com/emacs-compat/compat"
> :doc "compat.texi")
> + (constants :url "https://github.com/cdominik/constants-for-Emacs"
> + :ignored-files ("Makefile"))
There is no need for an :ignored-files here, you can track the files you
wish to exclude from the tarball using a .elpaignore file in the root
directory of your repository.
> (consult :url "https://github.com/minad/consult"
> :doc "README.org"
> :news "CHANGELOG.org"
Here are a few general comments, suggestions and fixes:
[-- Attachment #2: Type: text/plain, Size: 17762 bytes --]
diff --git a/constants.el b/constants.el
index 99eb76c..324bb3a 100644
--- a/constants.el
+++ b/constants.el
@@ -26,9 +26,9 @@
;; Boston, MA 02111-1307, USA.
;;---------------------------------------------------------------------------
-;;
+
;;; Commentary:
-;;
+
;; When I write small programs to calculate something, I often need
;; the values of some physical constants and units. I could of course
;; always link a big module with all those definitions. But often I
@@ -62,9 +62,9 @@
;; MATLAB, OCTAVE, PERL, EMACS-LISP, GP. You can change these
;; defaults and add definitions for other languages with the variable
;; `constants-languages'.
-;;
-;; INSTALLATION
-;; ------------
+
+;;;; Installation
+
;; Put this file on your load path, byte compile it, and copy the
;; following code into your .emacs file. Change the key definitions,
;; variable name aliasing and the unit system to your liking.
@@ -83,9 +83,9 @@
;;
;; ;; A default list of constants to insert when none are specified
;; (setq constants-default-list "cc,bk,hp")
-;;
-;; USAGE
-;; -----
+
+;;;; Usage
+
;; In a programming mode, call the function and at the prompt enter
;; for example
;;
@@ -115,10 +115,9 @@
;; 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
-;; -------------
+
+;;;; Customization
+
;; The following customization variables are available:
;;
;; constants-unit-system
@@ -144,9 +143,9 @@
;;
;; constants-prefixes
;; Allowed prefixes for constants and units.
-;;
-;; CONTEXT SENSITIVITY
-;; -------------------
+
+;;;; Context Sensitivity
+
;; For some languages, it might be usefull to adapt the inserted code
;; to context. For example, in Emacs Lisp mode, the default settings
;; insert "(VARIABLE VALUE)" with surrounding parenthesis for a `let'
@@ -172,9 +171,9 @@
;; (lambda ()
;; (setq constants-language-function
;; 'my-constants-elisp-function)))
-;;
-;; BUGS
-;; ----
+
+;;;; Bugs
+
;; - Completion does not consider prefixes. For example, you cannot
;; complete "MGa" to "MGauss" (meaning "Mega-Gauss"). This was not
;; implemented because it would cause too many matches during
@@ -190,26 +189,26 @@
;; - I have tried to implement the cgs units correctly, but I have
;; some doubt about the electrical and radiation units.
;; Double-check before blindly using these.
-;;
-;; AUTHOR
-;; ------
+
+;;;; Author
+
;; Carsten Dominik <carsten.dominik@gmail.com>
;;
;; Let me know if you are missing a constant in the default setup, if
;; you notice that a value of a constant is not correct, or if you
;; would like to see support for another language mode.
-;;
-;; ACKNOWLEDGEMENTS
-;; ----------------
+
+;;;; ACKNOWLEDGEMENTS
+
;; Thanks to Kees Dullemond. Watching him writing programs has
;; inspired this package.
;;
;; Thanks to the following people for reporting bugs and/or suggesting
;; features/constants/languages:
;; Bruce Ignalis, Dave Pearson, Jacques L'helgoualc'h, Federico Beffa
-;;
-;; CHANGES
-;; -------
+
+;;; News
+
;; Version 2.10
;; - Ready for becoming an ELPA package
;;
@@ -237,9 +236,9 @@
;; the syntax "varname=const".
;; - Support for shell-like modes like idlwave-shell-mode.
;; - XEmacs support (fixed a small bug)
-;;
-;; TO DO
-;; -----
+
+;;;; TO DO
+
;; - Support more programming languages.
;; - Add expression values tcl and others.
;; - Add calc mode?
@@ -250,7 +249,7 @@
;; - add a command to get info about a certain variable. Only useful if
;; the variable name really is the constant name. Not sure if this will
;; be used at all, so until someones asks for it, this will not be done.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
;;
;;; Code:
@@ -263,12 +262,13 @@
(defcustom constants-unit-system 'SI
"The unit system to be used for the constants.
-Legal values are `cgs' and `SI'."
- :group 'constants
+Legal values are `cgs' (centimetre-gram-second) and `SI'."
:type '(choice
(const cgs)
(const SI)))
+;; how hard is the dependency on Emacs 24.1? With 24.3 we have
+;; defvar-local, that slightly simplifies blocks like these:
(defvar constants-unit-system-override nil)
(make-variable-buffer-local 'constants-unit-system-override)
@@ -286,9 +286,8 @@ be the name of a user-defined or default constant. See the variables
`constants-defaults' and `constants-user-defined'."
:group 'constants
:type
- '(repeat
- (cons (string "Variable name")
- (string "Constant name"))))
+ '(alist :key-type (string :tag "Variable name")
+ :value-type (string :tag "Constant name")))
(defcustom constants-user-defined nil
"User defined constants for programs.
@@ -313,7 +312,6 @@ SI-value is a symbol like `fortran-mode', the expressions for the
corresponding mode will be looked up. If the SI-value is the empty
string or the symbol `default', settings for a virtual mode `default'
are used. Again, `constants-defaults' contains examples."
- :group 'constants
:type '(repeat
(list
(string :tag "Long name")
@@ -328,9 +326,8 @@ are used. Again, `constants-defaults' contains examples."
(string :tag "cgs value"))))))
-(defcustom constants-default-list "hp,kk,cc,AU,Msun,Lsun,Grav"
+(defcustom constants-default-list "hp,kk,cc,AU,Msun,Lsun,Grav" ;why not a list?
"Default constants to insert if none are specified."
- :group 'constants
:type 'string)
(defcustom constants-languages
@@ -388,7 +385,6 @@ In this case, the language settings are copied from other-major-mode.
This is mainly useful for modes which have several incarnations, like
`emacs-lisp-mode' and `lisp-interaction-mode', or `perl-mode' and
`cperl-mode'."
- :group 'constants
:type
'(repeat
(choice
@@ -405,7 +401,6 @@ This is mainly useful for modes which have several incarnations, like
(defcustom constants-indent-code t
"Non-nil means, indent the newly inserted code according to mode."
- :group 'constants
:type 'boolean)
(defconst constants-defaults
@@ -676,7 +671,6 @@ This is mainly useful for modes which have several incarnations, like
(defcustom constants-allow-prefixes t
"Non-nil means, non-matching names are checked to have unit prefixes.
See `constants-prefixes' for a list of allowed prefixes."
- :group 'constants
:type 'boolean)
(defcustom constants-prefixes
@@ -697,10 +691,9 @@ See `constants-prefixes' for a list of allowed prefixes."
(?f "1e-15" "Femto")
(?a "1e-18" "Atto"))
"Allowed prefixes for constants and units."
- :group 'constants
:type '(repeat
(list (character :tag "Prefix char")
- (number :tag "Numeric value")
+ (number :tag "Numeric value") ;the above are not numbers!
(string :tag "Prefix name"))))
(defvar constants-language-function nil
@@ -716,16 +709,14 @@ The value of this variable must be a function which returns a list
(defun constants-is-lisp-like (mode)
"Is MODE a lisp-like mode?"
- (save-match-data
- (string-match "\\(lisp\\|scheme\\)" (symbol-name mode))))
+ (string-match-p "\\(lisp\\|scheme\\)" (symbol-name mode)))
(defun constants-is-set-like ()
"Is this a setq-like form?"
(save-excursion
(condition-case nil
- (save-match-data
- (progn (up-list -1)
- (or (looking-at "(set[qf!]?\\>") (looking-at "(define\\>"))))
+ (progn (up-list -1)
+ (looking-at-p "\\(?:(set[!fq]\\|(define\\)\\_>"))
(error nil)))) ; return value nil means use default
;;;###autoload
@@ -735,12 +726,15 @@ The value of this variable must be a function which returns a list
'(emacs-lisp-mode "%n %v%t; %d %u" "e" "(* %p %v)")
'(emacs-lisp-mode "(%n %v)%t; %d %u" "e" "(* %p %v)")))
+;; Is this not a tad invasive? Wouldn't it be better to provide a
+;; `constant-init' function that users can manually add to these
+;; hooks?
;;;###autoload
(mapc (lambda (mode-hook)
(add-hook mode-hook
(lambda ()
(setq constants-language-function
- '#constants-lisp-like-function))))
+ #'constants-lisp-like-function))))
'(scheme-mode-hook emacs-lisp-mode-hook lisp-mode-hook))
;;;###autoload
@@ -771,7 +765,7 @@ 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
`cgs' may be specified directly. For example
- (constants-insert 'SI \"hplanck,c,M*pc\")"
+ (constants-insert \\='SI \"hplanck,c,M*pc\")"
(interactive "P")
(let* ((constants-unit-system
(cond ((and unit-system (symbolp unit-system)) unit-system)
@@ -794,6 +788,10 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but also `SI' or
(assq mode constants-languages)
(assq t constants-languages)))
format exp-string unit-system
+ ;; some more unused variable warnings here: `name' appears to
+ ;; actually be used, so I am not sure what is going on there,
+ ;; `rpl' is rebound later on and `beg' actually doesn't occur
+ ;; anywhere.
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
@@ -894,13 +892,14 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but also `SI' or
(progn
(while (string-match "%t" ins)
(setq ins (replace-match
- (make-string (max 2 (- 38 (match-beginning 0))) ?\ )
+ (make-string (max 2 (- 38 (match-beginning 0))) ?\s)
t t ins)))
(funcall process-func ins))
;; Here comes the insertion stuff for source code editing modes.
;; First make sure we start a new line
- (if (and (string-match
- "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
+ (if (and (save-excursion
+ (goto-char (line-beginning-position))
+ (looking-at "\\S-"))
(not (constants-is-lisp-like mode)))
;; non-empty line, insert after this line
(progn
@@ -919,12 +918,11 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but also `SI' or
(or (constants-is-set-like)
(null clist)))
(save-excursion
- (progn
- (move-to-column comment-column t)
- (insert (match-string 2 line))
- ;; insert a newline such that paredit's M-) can mode
- ;; the closing parentheses to the next line.
- (newline-and-indent)))
+ (move-to-column comment-column t)
+ (insert (match-string 2 line))
+ ;; insert a newline such that paredit's M-) can mode
+ ;; the closing parentheses to the next line.
+ (newline-and-indent))
(progn
(indent-to comment-column)
(insert (match-string 2 line)))))
@@ -933,6 +931,7 @@ NAMES. UNIT-SYSTEM may be nil to use the default, but also `SI' or
(if constants-indent-code
(newline-and-indent)
(newline)))))))
+
;;;###autoload
(defun constants-get (&optional const message unit-system)
"Return the value of CONST as defined in the constants package.
@@ -960,7 +959,7 @@ bahavior also in a programmatic call."
(or const
(error "Non-interactive use must supply the name of a constant")))
(setq entry (constants-assoc const atable 'follow)
- pmatch (assoc (string-to-char const) constants-prefixes))
+ pmatch (assq (string-to-char const) constants-prefixes))
(and (not entry)
constants-allow-prefixes
pmatch
@@ -1024,7 +1023,7 @@ For example \"pi\" would be replaced by \"3.1415926535897932385\"."
(defun constants-set-unit-system (system)
"Set unit system to SYSTEM and make sure it persists in this buffer."
- (if (equal (downcase system) "cgs")
+ (if (string-equal (downcase system) "cgs")
(setq constants-unit-system 'cgs
constants-unit-system-override 'cgs)
(setq constants-unit-system 'SI
@@ -1049,8 +1048,8 @@ For example \"pi\" would be replaced by \"3.1415926535897932385\"."
(match-string 1 val)
val)))
-(defun constants-get-unit (entry &optional mode)
- "Extract the unit string from the ENTRY. MODE will be ignored."
+(defun constants-get-unit (entry &optional _mode)
+ "Extract the unit string from the ENTRY."
(let ((val (cond ((eq constants-unit-system 'SI) (nth 3 entry))
((eq constants-unit-system 'cgs) (nth 4 entry))
(t nil))))
@@ -1061,7 +1060,7 @@ For example \"pi\" would be replaced by \"3.1415926535897932385\"."
(defun constants-assoc (key table &optional follow)
"Case-insensitive assoc on first and second list element, using KEY and TABLE.
When FOLLOW is non-nil, check if the match is a rename cell
-and follow it up."
+and follow it up." ;follow is ignored!
(catch 'exit
(let ((key1 (downcase key)) entry)
(while (setq entry (car table))
@@ -1089,7 +1088,7 @@ and follow it up."
(unwind-protect
(progn
(setq-default completion-ignore-case t)
- (apply 'completing-read (car args)
+ (apply #'completing-read (car args)
'constants-completion-function
(cdr (cdr args))))
(setq-default completion-ignore-case old-value))))
@@ -1112,7 +1111,7 @@ and follow it up."
(let ((all
(delq nil
(append
- (mapcar 'car varnames)
+ (mapcar #'car varnames)
(mapcar (lambda(x) (if (consp x) (car x)))
constants)
(mapcar (lambda(x) (if (consp x) (nth 1 x)))
@@ -1138,11 +1137,11 @@ STRING, PREDICATE, and FLAG are the usual completion parameters."
(cond
((eq flag nil)
;; try completion
- (setq rtn (try-completion s2 constants-ctable))
+ (setq rtn (try-completion s2 constants-ctable predicate))
(if (stringp rtn) (concat s1 s2 (substring rtn (length s2)))))
((eq flag t)
;; all-completions
- (all-completions s2 constants-ctable))
+ (all-completions s2 constants-ctable predicate))
((eq flag 'lambda)
;; exact match?
(assoc s2 constants-ctable)))))
@@ -1154,9 +1153,8 @@ The values are for the currently selected unit system. 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. If COMPLETING is non-lil, use completion."
-
(interactive "P")
- (with-output-to-temp-buffer "*Help*"
+ (with-help-window "*Help*"
(let* ((constants-unit-system
(cond ((and unit-system (symbolp unit-system)) unit-system)
(unit-system (if (eq constants-unit-system 'SI) 'cgs 'SI))
@@ -1174,11 +1172,11 @@ used. I.e., if your default is `SI', then a prefix arg will switch to
(if constants-user-defined (setq all (cons "User defined entries" all)))
(princ (format
-" List of constants: %s
+ " List of constants: %s
Description Short Long name Value [%s]
-------------------------------------------------------------------------------
"
-(if completing "Use Shift-<TAB> to scroll" "") us))
+ (if completing "Use Shift-<TAB> to scroll" "") us))
(while (setq entry (pop all))
(if (stringp entry)
(progn
@@ -1191,7 +1189,7 @@ Description Short Long name Value [%s]
(nth 2 entry) (nth 1 entry) (nth 0 entry)
(constants-get-value entry mode)
(constants-get-unit entry mode))))))
-(let ((all constants-rename) entry)
+ (let ((all constants-rename) entry)
(princ "\nRenaming\n--------\n")
(while (setq entry (pop all))
(princ (format "%-15s refers to `%s'\n" (car entry) (cdr entry)))))
@@ -1203,7 +1201,7 @@ Description Short Long name Value [%s]
(let* ((all-constants (append constants-user-defined constants-defaults))
(atable (append constants-rename all-constants))
(constants-ctable (constants-make-completion-table constants-rename
- all-constants))
+ all-constants))
const c1ass c1)
(princ "
The following ambiguities are resolved by ignoring the unit prefix
@@ -1228,8 +1226,7 @@ The following ambiguities are resolved by ignoring the unit prefix
(defun constants-test (names)
"Test `constants-insert' with NAMES for several different modes.
-To try it out, type '(constants-test)' into a buffer, put the cursor after
-the closing parenthesis and execute \\[eval-last-sexp]."
+To try it out, evaluate \\='(constants-test)' using \\[eval-expression]."
(let ((modes '(fortran-mode c-mode emacs-lisp-mode lisp-interaction-mode
idlwave-mode perl-mode cperl-mode))
mode)
@@ -1241,5 +1238,4 @@ the closing parenthesis and execute \\[eval-last-sexp]."
(normal-mode)))
(provide 'constants)
-
;;; constants.el ends here
[-- Attachment #3: Type: text/plain, Size: 37 bytes --]
--
Philip Kaludercic on peregrine
^ permalink raw reply related [flat|nested] 3+ messages in thread