Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
precision-mode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alberto Ramos
precision-mode
Commits
ec85045f
Commit
ec85045f
authored
Jan 13, 2019
by
Alberto Ramos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Iinital version of Emacs precision-model.el
parents
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
218 additions
and
0 deletions
+218
-0
README.md
README.md
+46
-0
screencast/precision-mode.gif
screencast/precision-mode.gif
+0
-0
src/precision-mode.el
src/precision-mode.el
+172
-0
No files found.
README.md
0 → 100644
View file @
ec85045f
# precision-mode.el: Change format of data with uncertainties
This simple emacs minor mode helps converting numerical values with
uncertainties between human readable and computer readable formats.
## Install
Just copy the file
`precision-mode.el`
with the rest of your emacs
configuration files and add tou your
`.emacs`
file
```
(precision-mode)
```
## Usage
At the moment the mode has some very simple features
-
`M-x prec-pm-to-paren`
: Transforms values in the format
`value +/-
error`
into the human readable
`value(error)`
.
-
`M-x prec-paren-to-pm`
: Performs the inverse transformation.
The variable
`prec-ndigits`
contains the number of significant digits
for the errors (default: 2). If you prefer a different formatting
option change the value with (i.e.
`(setq prec-ndigits 3)`
) before
loading the minor mode.
## Screencast
This screencast shows one of the most frequent uses. Some text output
from an analysis code is transformed to human readable format by
`precision-mode`
. Together with
`orgtbl-mode`
the data can be easily
exported to a
`LaTeX`
file.
![
Screencast
](
screencast/precision-mode.gif
)
## License
```
"THE BEER-WARE LICENSE":
Alberto Ramos wrote this file. As long as you retain this
notice you can do whatever you want with this stuff. If we meet some
day, and you think this stuff is worth it, you can buy me a beer in
return. <alberto.ramos@cern.ch>
```
screencast/precision-mode.gif
0 → 100644
View file @
ec85045f
1.66 MB
src/precision-mode.el
0 → 100644
View file @
ec85045f
;;
;; precision-mode.el
;;
;; "THE BEER-WARE LICENSE":
;; Alberto Ramos wrote this file. As long as you retain this
;; notice you can do whatever you want with this stuff. If we meet some
;; day, and you think this stuff is worth it, you can buy me a beer in
;; return. <alberto.ramos@cern.ch>
;;
;; file: precision-mode.el
;; created: Fri Jun 29 2018
;;
;; DESCRIPTION:
;;
;; precision-mode provides simple routines to write data with
;; uncertainties in human readable format.
;;
;;
;; USAGE:
;;
;; Add (precision-mode) to your .emacs file
;;
;;
;; Variables:
;;
;; (setq prec-ndigits 3): Set the number of significant digits in
;; the errors.
;;
;;
;; Functions:
;;
;; M-x prec-pm-to-paren: Change numbers with uncertainties in the
;; format val +/- error to the human readable format val(err).
;;
;; M-x prec-paren-to-pm: Change numbers in human readable format
;; val(error) to the format val +/- error.
;;
;;
;; TODO
;;
;; At the moment this minor mode is just a simple collection of a few
;; routines to change fotmat of numbers.
;;
(
defvar
prec-ndigits
2
"Number of significant digits in error"
)
(
defun
prec-all-to-paren
()
"Substitute val err or val +/- err to val(err)"
(
interactive
)
(
save-restriction
(
narrow-to-region
(
region-beginning
)
(
region-end
))
(
goto-char
(
point-min
))
(
while
(
search-forward-regexp
"[+-]?[0-9]*\\.[0-9]*\\([eE]?[+-]?[0-9]+\\)?[[:space:]]+\\(+/-\\)?[[:space:]]+[+-]?[0-9]*\\.[0-9]*\\([eE]?[+-]?[0-9]+\\)?"
nil
t
)
(
save-match-data
(
setq
str
(
split-string
(
match-string
0
))
)
(
setq
v
(
nth
0
str
))
(
setq
dv
(
nth
1
str
))
(
if
(
=
(
length
str
)
3
)
(
setq
dv
(
nth
2
str
))
(
setq
dv
(
nth
1
str
))
)
)
(
replace-match
(
prec-print-paren
(
string-to-number
v
)
(
string-to-number
dv
))
)
)
)
)
(
defun
prec-paren-to-pm
()
"Substitute val(err) to val +/- err"
(
interactive
)
(
save-restriction
(
narrow-to-region
(
region-beginning
)
(
region-end
))
(
goto-char
(
point-min
))
(
while
(
search-forward-regexp
"[+-]?[0-9]*\\.[0-9]*([0-9]+)"
nil
t
)
(
save-match-data
(
setq
str
(
split-string
(
match-string
0
)
"("
))
(
setq
v
(
nth
0
str
))
(
setq
dv
(
substring
(
nth
1
str
)
0
-1
))
(
setq
nerr
(
length
dv
))
(
setq
ndec
(
length
(
nth
1
(
split-string
v
"\\."
))))
(
setq
ddv
(
/
(
string-to-number
(
concat
dv
".0"
))
(
expt
10
ndec
)))
)
(
replace-match
(
prec-print-pm
(
string-to-number
v
)
ddv
)
)
)
)
)
(
defun
prec-pm-to-paren
()
"Substitute val+/-err to val(err)"
(
interactive
)
(
save-restriction
(
narrow-to-region
(
region-beginning
)
(
region-end
))
(
goto-char
(
point-min
))
(
while
(
search-forward-regexp
"[+-]?[0-9]*\\.[0-9]*\\([eE]?[+-]?[0-9]+\\)?[[:space:]]*\\(+/-\\)[[:space:]]*[+-]?[0-9]*\\.[0-9]*\\([eE]?[+-]?[0-9]+\\)?"
nil
t
)
(
save-match-data
(
setq
str
(
split-string
(
match-string
0
)
"+/-"
)
)
(
setq
v
(
nth
0
str
))
(
if
(
=
(
length
str
)
3
)
(
setq
dv
(
nth
2
str
))
(
setq
dv
(
nth
1
str
))
)
)
(
replace-match
(
prec-print-paren
(
string-to-number
v
)
(
string-to-number
dv
))
)
)
)
)
(
defun
prec-error-to-paren
()
"Substitute val err to val(err)"
(
interactive
)
(
save-restriction
(
narrow-to-region
(
region-beginning
)
(
region-end
))
(
goto-char
(
point-min
))
(
while
(
search-forward-regexp
"[+-]?[0-9]*\\.[0-9]*\\([eE]?[+-]?[0-9]+\\)?[[:space:]]+[+-]?[0-9]*\\.[0-9]*\\([eE]?[+-]?[0-9]+\\)?"
nil
t
)
(
save-match-data
(
setq
str
(
split-string
(
match-string
0
))
)
(
setq
v
(
nth
0
str
))
(
setq
dv
(
nth
1
str
))
)
(
replace-match
(
prec-print-paren
(
string-to-number
v
)
(
string-to-number
dv
))
)
)
)
)
(
defun
prec-print-paren
(
val
err
)
"Print val err with val(err) format"
(
setq
prec
(
truncate
(
log10
(
+
err
(
/
err
100000.
)))))
(
if
(
<=
prec
0
)
(
setq
ndec
(
+
(
-
prec
)
prec-ndigits
))
(
setq
ndec
0
)
)
(
if
(
and
(
<
err
10.0
)
(
>=
err
1.0
))
(
setq
ndec
(
-
ndec
1
))
)
(
setq
fmt
(
concat
"\%12."
(
format
"%d"
ndec
)
"f"
))
(
setq
fmt
(
concat
fmt
"(%d)"
))
(
format
fmt
val
(
round
(
*
err
(
expt
10
ndec
))))
)
(
defun
prec-print-pm
(
val
err
)
"Print val err with val +/- err format"
(
if
(
<
val
99.999999
)
(
format
"%.8f +/- %.4e"
val
err
)
(
format
"%.8e +/- %.4e"
val
err
)
)
)
(
define-minor-mode
precision-mode
"Toggle Precision mode."
;; The initial value.
nil
;; The indicator for the mode line.
:lighter
" Prec"
;; The minor mode bindings.
:keybindings
:group
'precision
)
(
provide
'precision-mode
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment