From 50ec5643de3af8c70062eed12a86cc86e92621de Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 30 Jul 2018 20:02:49 +0200 Subject: [PATCH] Move functions from round-number-to-decimals.el to the Org config --- configuration.org | 26 ++++++++++++++++++++++++++ init.el | 1 - lisp/round-number-to-decimals.el | 17 ----------------- 3 files changed, 26 insertions(+), 18 deletions(-) delete mode 100644 lisp/round-number-to-decimals.el diff --git a/configuration.org b/configuration.org index b5c6f1b..49368c9 100644 --- a/configuration.org +++ b/configuration.org @@ -68,6 +68,32 @@ I set it up early so I can use it in ~use-package~ calls immediately. (mapcar (lambda (x) (and (stringp x) x)) var)))))) #+END_SRC +*** Get the number at point + +#+BEGIN_SRC emacs-lisp +(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))) +#+END_SRC + +*** Round number at point to the given decimals + +#+BEGIN_SRC emacs-lisp +(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))))) +#+END_SRC + ** Check if we are running under Termux We need to do things differently, if so. diff --git a/init.el b/init.el index b4a3a80..9368cd8 100644 --- a/init.el +++ b/init.el @@ -27,7 +27,6 @@ ;; Load my own functions (load "gnu-c-header") -(load "round-number-to-decimals") ;; From gmane.emacs.orgmode ;; (http://article.gmane.org/gmane.emacs.orgmode/75222) diff --git a/lisp/round-number-to-decimals.el b/lisp/round-number-to-decimals.el deleted file mode 100644 index e2dc465..0000000 --- a/lisp/round-number-to-decimals.el +++ /dev/null @@ -1,17 +0,0 @@ -(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)))))