diff options
| author | Juanma Barranquero | 2014-03-20 19:22:17 +0100 |
|---|---|---|
| committer | Juanma Barranquero | 2014-03-20 19:22:17 +0100 |
| commit | 4539380159e6ed1cd79418bd34e28ebf0485a510 (patch) | |
| tree | 11dbbb402d3465be82269aba2d511e95ae8c8e8a | |
| parent | 814e26fa05d6496867bd99cf05bc57ce2e6c4d4b (diff) | |
| download | emacs-4539380159e6ed1cd79418bd34e28ebf0485a510.tar.gz emacs-4539380159e6ed1cd79418bd34e28ebf0485a510.zip | |
lisp/progmodes/hideif.el (hif-tokenize): Understand non-decimal floats.
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/progmodes/hideif.el | 17 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 51d5de2f3be..30e76c013b7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2014-03-20 Juanma Barranquero <lekktu@gmail.com> | 1 | 2014-03-20 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 2 | ||
| 3 | * progmodes/hideif.el (hif-string-to-number): New function. | ||
| 4 | (hif-tokenize): Use it to understand non-decimal floats. | ||
| 5 | |||
| 3 | * emacs-lisp/cl-extra.el (cl--map-overlays): Remove obsolete code. | 6 | * emacs-lisp/cl-extra.el (cl--map-overlays): Remove obsolete code. |
| 4 | 7 | ||
| 5 | * skeleton.el (skeleton-autowrap): Mark as obsolete. Doc fix. | 8 | * skeleton.el (skeleton-autowrap): Mark as obsolete. Doc fix. |
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el index 39ad676f593..bcb46592465 100644 --- a/lisp/progmodes/hideif.el +++ b/lisp/progmodes/hideif.el | |||
| @@ -407,6 +407,14 @@ that form should be displayed.") | |||
| 407 | 407 | ||
| 408 | (defconst hif-string-literal-regexp "\\(\"\\(?:[^\"\\]\\|\\\\.\\)*\"\\)") | 408 | (defconst hif-string-literal-regexp "\\(\"\\(?:[^\"\\]\\|\\\\.\\)*\"\\)") |
| 409 | 409 | ||
| 410 | (defun hif-string-to-number (string &optional base) | ||
| 411 | "Like `string-to-number', but it understands non-decimal floats." | ||
| 412 | (if (or (not base) (= base 10)) | ||
| 413 | (string-to-number string base) | ||
| 414 | (let* ((parts (split-string string "\\." t "[ \t]+")) | ||
| 415 | (frac (cadr parts)) | ||
| 416 | (quot (expt (* base 1.0) (length frac)))) | ||
| 417 | (/ (string-to-number (concat (car parts) frac) base) quot)))) | ||
| 410 | 418 | ||
| 411 | (defun hif-tokenize (start end) | 419 | (defun hif-tokenize (start end) |
| 412 | "Separate string between START and END into a list of tokens." | 420 | "Separate string between START and END into a list of tokens." |
| @@ -433,15 +441,12 @@ that form should be displayed.") | |||
| 433 | ;; TODO: | 441 | ;; TODO: |
| 434 | ;; 1. postfix 'l', 'll', 'ul' and 'ull' | 442 | ;; 1. postfix 'l', 'll', 'ul' and 'ull' |
| 435 | ;; 2. floating number formats | 443 | ;; 2. floating number formats |
| 436 | ;; 3. hexadecimal/octal floats | 444 | ;; 3. 098 is interpreted as octal conversion error |
| 437 | ;; 4. 098 is interpreted as octal conversion error | ||
| 438 | ;; FIXME: string-to-number does not convert hex floats | ||
| 439 | (if (string-match "0x\\([0-9a-fA-F]+\\.?[0-9a-fA-F]*\\)" | 445 | (if (string-match "0x\\([0-9a-fA-F]+\\.?[0-9a-fA-F]*\\)" |
| 440 | token) | 446 | token) |
| 441 | (string-to-number (match-string 1 token) 16)) ;; hex | 447 | (hif-string-to-number (match-string 1 token) 16)) ;; hex |
| 442 | ;; FIXME: string-to-number does not convert octal floats | ||
| 443 | (if (string-match "\\`0[0-9]+\\(\\.[0-9]+\\)?\\'" token) | 448 | (if (string-match "\\`0[0-9]+\\(\\.[0-9]+\\)?\\'" token) |
| 444 | (string-to-number token 8)) ;; octal | 449 | (hif-string-to-number token 8)) ;; octal |
| 445 | (if (string-match "\\`[1-9][0-9]*\\(\\.[0-9]+\\)?\\'" | 450 | (if (string-match "\\`[1-9][0-9]*\\(\\.[0-9]+\\)?\\'" |
| 446 | token) | 451 | token) |
| 447 | (string-to-number token)) ;; decimal | 452 | (string-to-number token)) ;; decimal |