Add round-number-to-decimal.el
This commit is contained in:
parent
ce0f26fa86
commit
adf5f39439
1
init.el
1
init.el
@ -63,6 +63,7 @@
|
|||||||
(load "gnu-c-header.el")
|
(load "gnu-c-header.el")
|
||||||
(load "gobgen/gobgen.el")
|
(load "gobgen/gobgen.el")
|
||||||
(load "toggle-window-split.el")
|
(load "toggle-window-split.el")
|
||||||
|
(load "round-number-to-decimals.el")
|
||||||
|
|
||||||
(add-hook 'c-mode-hook 'helm-gtags-mode)
|
(add-hook 'c-mode-hook 'helm-gtags-mode)
|
||||||
(add-hook 'c-mode-hook 'which-func-mode)
|
(add-hook 'c-mode-hook 'which-func-mode)
|
||||||
|
19
round-number-to-decimals.el
Normal file
19
round-number-to-decimals.el
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
(defun get-number-at-point ()
|
||||||
|
(interactive)
|
||||||
|
(skip-chars-backward "0123456789.-")
|
||||||
|
(or (looking-at "[0123456789.-]+")
|
||||||
|
(error "No number at point"))
|
||||||
|
(string-to-number (match-string 0)))
|
||||||
|
|
||||||
|
(defun round-number-at-point-to-decimals (decimal-count)
|
||||||
|
(interactive "NDecimal count: ")
|
||||||
|
(let ((mult (expt 10 decimal-count)))
|
||||||
|
(replace-match (number-to-string
|
||||||
|
(/
|
||||||
|
(fround
|
||||||
|
(*
|
||||||
|
mult
|
||||||
|
(get-number-at-point)))
|
||||||
|
mult)))))
|
||||||
|
|
||||||
|
(global-set-key (kbd "C-c r") 'round-number-at-point-to-decimals)
|
Loading…
Reference in New Issue
Block a user