* PATCH: num3-mode for highlighting groups of digits in long numbers @ 2012-09-06 16:21 Michal Nazarewicz 2012-09-06 17:23 ` Lars Ingebrigtsen ` (2 more replies) 0 siblings, 3 replies; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-06 16:21 UTC (permalink / raw) To: emacs-devel; +Cc: Felix Lee [-- Attachment #1: Type: text/plain, Size: 5604 bytes --] Hello everyone, This time I bring to you a patch adding num3-mode which helps read long numbers by alternating highlighting of group of digits in a long number, so for instance something like: 12345678.12345678 would be displayed as ("-" symbolising underscore): 12345678.12345678 --- --- This also works for hexadecimal numbers by grouping 4-digits at a time, ie.: 0x0123456789ABCDEF ---- ---- The face is customisable and can be added to both odd and even groups. ---------- >% ------------------------------------------------------------ === modified file 'etc/NEWS' --- etc/NEWS 2012-09-06 09:29:32 +0000 +++ etc/NEWS 2012-09-06 15:48:03 +0000 @@ -539,6 +539,11 @@ \f * New Modes and Packages in Emacs 24.3 + +** num3-mode is a minor mode that highlights groups of digits in a long +numbers thus so as to make it easier to read. Enable in current +buffer via M-x num3-mode RET or globally via M-x global-num3-mode RET. + \f * Incompatible Lisp Changes in Emacs 24.3 === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-09-06 15:35:08 +0000 +++ lisp/ChangeLog 2012-09-06 15:49:32 +0000 @@ -1,3 +1,7 @@ +2012-09-06 Michal Nazarewicz <mina86@mina86.com> + + * num3.el: New num3-mode minor mode. + 2012-09-06 Stefan Monnier <monnier@iro.umontreal.ca> * emacs-lisp/cl-macs.el (cl--do-arglist): Understand _ on &key args === added file 'lisp/num3.el' --- lisp/num3.el 1970-01-01 00:00:00 +0000 +++ lisp/num3.el 2012-09-06 16:09:55 +0000 @@ -0,0 +1,122 @@ +;;; num3-mode.el --- highlight groups of digits in long numbers -*- lexical-binding: t -*- + +;; Copyright (C) 2012 Free Software Foundation, Inc. + +;; Author: Felix Lee <felix8a@gmail.com> +;; Michal Nazarewicz <mina86@mina86.com> +;; Keywoards: faces, minor-mode + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Num3 is a minor mode that makes long numbers more readable by +;; highlighting groups of 3 (customisable) decimal digits or 4 hex +;; digits when font-lock is on. Highlighting alternates between two +;; faces that can be customised. + +;;; Usage: + +;; M-x num3-mode toggle for current buffer. +;; M-x global-num3-mode toggle for all buffers. +;; +;; Or add the following to your ~/.emacs file: +;; (load "path/to/num3") +;; (global-num3-mode) + +;;; User variables: + +(defgroup num3 nil + "Num3 is a minor mode that makes long numbers more readable by +highlighting groups of 3 decimal digits or 4 hex digits when +font-lock is on." + :group 'text) + +(defcustom num3-group-size 3 + "Number of digits to group in decimal numbers.") + +(defcustom num3-threshold 5 + "Number must be at least that long to start highlighting.") + +(defface num3-face-odd + '((t)) + "Face to add for odd groups of digits." + :group 'num3) + +(defface num3-face-even + '((t :underline t :weight bold :background "#eeeeee")) + "Face to add for even groups of digits. +The default face uses redundant signaling, because this is in +addition to any other font-lock highlighting." + :group 'num3) + +;;; Implementation: + +(require 'font-lock) + +;;;###autoload +(define-minor-mode num3-mode + "Toggle num3 minor mode in the current buffer. +Num3 minor mode makes long numbers more readable by +highlighting groups of 3 digits when font-lock is on." + nil " num3" nil + (if num3-mode + (unless (assoc '-num3-matcher font-lock-keywords) + (font-lock-add-keywords nil '(-num3-matcher) 'append)) + (font-lock-remove-keywords nil '(-num3-matcher))) + (when font-lock-mode + (font-lock-fontify-buffer))) + +;;;###autoload +(define-globalized-minor-mode global-num3-mode num3-mode turn-on-num3-mode) + +;;;###autoload +(defun turn-on-num3-mode () + "Turns on `num3-mode' if it's not enabled." + (unless num3-mode (num3-mode t))) + +(defconst -num3-number-re + (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal + "\\|\\([0-9]+\\)" ; 2 = decimal + "\\|\\.\\([0-9]+\\)")) ; 3 = fraction + +(defun -num3-matcher (lim) + (save-excursion + (while (re-search-forward -num3-number-re lim t) + (-num3-int (match-beginning 1) (match-end 1) 4) + (-num3-int (match-beginning 2) (match-end 2) num3-group-size) + (-num3-frac (match-beginning 3) (match-end 3) num3-group-size))) + nil) + +(defun -num3-int (lo hi n) + (when (and lo (>= (- hi lo) num3-threshold)) + (let (even) + (while (< lo hi) + (-num3-put even (max lo (- hi n)) hi) + (setq hi (- hi n) even (not even)))))) + +(defun -num3-frac (lo hi n) + (when (and lo (>= (- hi lo) num3-threshold)) + (let (even) + (while (< lo hi) + (-num3-put even lo (min hi (+ lo n))) + (setq lo (+ lo n) even (not even)))))) + +(defun -num3-put (even lo hi) + (font-lock-append-text-property lo hi 'face + (if even 'num3-face-even 'num3-face-odd))) + +(provide 'num3) [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-06 16:21 PATCH: num3-mode for highlighting groups of digits in long numbers Michal Nazarewicz @ 2012-09-06 17:23 ` Lars Ingebrigtsen 2012-09-06 21:22 ` Stefan Monnier 2012-09-06 23:18 ` Jambunathan K 2 siblings, 0 replies; 20+ messages in thread From: Lars Ingebrigtsen @ 2012-09-06 17:23 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: Felix Lee, emacs-devel Michal Nazarewicz <mpn@google.com> writes: > This time I bring to you a patch adding num3-mode which helps read long > numbers by alternating highlighting of group of digits in a long > number, so for instance something like: > > 12345678.12345678 That's a great idea. In my day job I deal with awkward big numbers all the time, and this would be really useful. -- (domestic pets only, the antidote for overdose, milk.) http://lars.ingebrigtsen.no * Lars Magne Ingebrigtsen ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-06 16:21 PATCH: num3-mode for highlighting groups of digits in long numbers Michal Nazarewicz 2012-09-06 17:23 ` Lars Ingebrigtsen @ 2012-09-06 21:22 ` Stefan Monnier 2012-09-25 20:40 ` Michal Nazarewicz 2012-09-06 23:18 ` Jambunathan K 2 siblings, 1 reply; 20+ messages in thread From: Stefan Monnier @ 2012-09-06 21:22 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: Felix Lee, emacs-devel > This time I bring to you a patch adding num3-mode which helps read long > numbers by alternating highlighting of group of digits in a long > number, so for instance something like: Looks nice, thanks. Tho I'd rather add it to GNU ELPA than to Emacs proper. Stefan ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-06 21:22 ` Stefan Monnier @ 2012-09-25 20:40 ` Michal Nazarewicz 2012-09-26 1:07 ` Stefan Monnier 0 siblings, 1 reply; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-25 20:40 UTC (permalink / raw) To: Stefan Monnier, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1113 bytes --] (Sorry for late response, I had to look at GNU ELPA but got sucked by other work in the meantime.) >> This time I bring to you a patch adding num3-mode which helps read long >> numbers by alternating highlighting of group of digits in a long >> number, so for instance something like: On Thu, Sep 06 2012, Stefan Monnier wrote: > Looks nice, thanks. Tho I'd rather add it to GNU ELPA than to > Emacs proper. Obviously, I would love to have it in Emacs, especially since it's tiny and I strongly believe it could benefit everyone by turning it on by default, but I could settle for a package if no one wants it in Emacs. ;) However, I could not figure out how would I go about preparing a package to go there. Emacswiki points to a overly-long thread with some pointers about policy, but no steps to get a package there. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-25 20:40 ` Michal Nazarewicz @ 2012-09-26 1:07 ` Stefan Monnier 2012-09-26 12:27 ` Michal Nazarewicz 0 siblings, 1 reply; 20+ messages in thread From: Stefan Monnier @ 2012-09-26 1:07 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: emacs-devel >>> This time I bring to you a patch adding num3-mode which helps read long >>> numbers by alternating highlighting of group of digits in a long >>> number, so for instance something like: >> Looks nice, thanks. Tho I'd rather add it to GNU ELPA than to >> Emacs proper. > Obviously, I would love to have it in Emacs, especially since it's tiny > and I strongly believe it could benefit everyone by turning it on by > default, but I could settle for a package if no one wants it in > Emacs. ;) I'm moving in the direction of keeping in Emacs only the "infrastructure" packages and leaving most of the end-user packages in GNU ELPA. Note that it doesn't necessarily mean it won't be included in Emacs. I hope that by Emacs-25, the Emacs tarball will be made up of Emacs proper plus some bundled ELPA packages so we can freely move packages to ELPA (e.g. for Gnus and Org). > However, I could not figure out how would I go about preparing a package > to go there. Emacswiki points to a overly-long thread with some > pointers about policy, but no steps to get a package there. For single-file packages, you just need to file to be structured correctly (try C-u M-x checkdoc-current-buffer) and have "Version:" and "Maintainer:" headers at the beginning. Also the packages need to have their copyright paperwork in order, just like code included with Emacs, so we can easily move code between the two. Stefan ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 1:07 ` Stefan Monnier @ 2012-09-26 12:27 ` Michal Nazarewicz 2012-09-26 12:56 ` Noah Lavine 0 siblings, 1 reply; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-26 12:27 UTC (permalink / raw) To: Stefan Monnier; +Cc: Felix Lee, emacs-devel [-- Attachment #1: Type: text/plain, Size: 7231 bytes --] On Wed, Sep 26 2012, Stefan Monnier wrote: > For single-file packages, you just need to file to be structured > correctly (try C-u M-x checkdoc-current-buffer) and have "Version:" > and "Maintainer:" headers at the beginning. Attached below. checkdoc-current-buffer gives me two errors but I'm not sure how to fix those since in given instances num3-mode refers to the mode. num3.el:102: Disambiguate num3-mode by preceding w/ function,command,variable,option or symbol. num3.el:111: Disambiguate num3-mode by preceding w/ function,command,variable,option or symbol. > Also the packages need to have their copyright paperwork in order, just > like code included with Emacs, so we can easily move code between > the two. Everything should be in order on that part. Google holds the Copyright, but it has the proper paperwork done (I have contributed previously). ---------- >% ---------------------------------------------------------- ;;; num3-mode.el --- highlight groups of digits in long numbers -*- lexical-binding: t -*- ;; Copyright (C) 2012 Free Software Foundation, Inc. ;; Author: Felix Lee <felix8a@gmail.com>, Michal Nazarewicz <mina86@mina86.com> ;; Maintainer: Michal Nazarewicz <mina86@mina86.com> ;; Version: 1.0 ;; Keywoards: faces, minor-mode ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: ;; Num3 is a minor mode that makes long numbers more readable by ;; highlighting groups of 3 (customisable) decimal digits or 4 hex ;; digits when font-lock is on. Highlighting alternates between two ;; faces that can be customised. ;;; Usage: ;; M-x num3-mode toggle for current buffer. ;; M-x global-num3-mode toggle for all buffers. ;; ;; Or add the following to your ~/.emacs file: ;; (load "path/to/num3") ;; (global-num3-mode) ;;; Code: (defgroup num3 nil "Num3 is a minor mode that makes long numbers more readable by highlighting groups of decimal digits or 4 hex digits when font-lock is on." :group 'text) (defcustom num3-group-size 3 "Number of digits to group in decimal numbers.") (defcustom num3-threshold 5 "Number must be at least that long to start highlighting.") (defface num3-face-odd '((t)) "Face to add for odd groups of digits." :group 'num3) (defface num3-face-even '((t :underline t :weight bold :background "#eeeeee")) "Face to add for even groups of digits. The default face uses redundant signaling, because this is in addition to any other font-lock highlighting." :group 'num3) ;;; Implementation: (require 'font-lock) ;;;###autoload (define-minor-mode num3-mode "Toggle num3 minor mode in the current buffer. Num3 minor mode makes long numbers more readable by highlighting groups of digits when font-lock mode is on. If a number is longer than `num3-threshold', the mode will split it into a group of `num3-group-size' (if number is decimal) or 4 (if number is hexadecimal) digits. Hexadecimal number is detected as one starting with 0x, 0X or #. With decimal numbers, fractions are recognised as well and grouped from the beginning rathar then from end. For instance, with group size of 3, a number \"12345.12345\" will be split into groups as follows: \"12|345.123|45\". Fractions without integer part are also recognised, eg. \".12345\". The groups are highlighted alternately using `num3-face-odd' and `num3-face-even' faces. `num3-face-even' face (which is empty by default) is the one used for the group closest to the decimal point." nil " num3" nil (if num3-mode (unless (assoc '-num3-matcher font-lock-keywords) (font-lock-add-keywords nil '(-num3-matcher) 'append)) (font-lock-remove-keywords nil '(-num3-matcher))) (when font-lock-mode (font-lock-fontify-buffer))) ;;;###autoload (define-globalized-minor-mode global-num3-mode num3-mode turn-on-num3-mode) ;;;###autoload (defun turn-on-num3-mode () "Turn `num3-mode' on if it's not enabled." (unless num3-mode (num3-mode t))) (defconst -num3-number-re (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal "\\|\\([0-9]+\\)" ; 2 = decimal "\\|\\.\\([0-9]+\\)")) ; 3 = fraction (defun -num3-matcher (lim) "Function used as a font-lock-keywoard handler used in `num3-mode'. Performs fontification of numbers from point to LIM." (save-excursion (while (re-search-forward -num3-number-re lim t) (-num3-int (match-beginning 1) (match-end 1) 4) (-num3-int (match-beginning 2) (match-end 2) num3-group-size) (-num3-frac (match-beginning 3) (match-end 3) num3-group-size))) nil) (defun -num3-int (lo hi n) "Highlight groups of digits in a long number. LO and HI arguments specify the range where the number is located. If the length of that region exceeds `num3-threshold', the function will split it into groups of N digits and fontify tham alternately using `num3-face-odd' and `num3-face-even' faces. Grouping is done from the end, eg. (12)(345)." (when (and lo (>= (- hi lo) num3-threshold)) (let (even) (while (< lo hi) (-num3-put even (max lo (- hi n)) hi) (setq hi (- hi n) even (not even)))))) (defun -num3-frac (lo hi n) "Highlight groups of digits in a long number. LO and HI arguments specify the range where the number is located. If the length of that region exceeds `num3-threshold', the function will split it into groups of N digits and fontify tham alternately using `num3-face-odd' and `num3-face-even' faces. Grouping is done from the beginning, eg. (123)(45)." (when (and lo (>= (- hi lo) num3-threshold)) (let (even) (while (< lo hi) (-num3-put even lo (min hi (+ lo n))) (setq lo (+ lo n) even (not even)))))) (defun -num3-put (even lo hi) "Add font lock text property to highlight a single group of digit. Use `num3-face-odd' if EVEN is nil and `num3-face-even' if EVEN is non-nil. The region the face is set to is from LO to HI." (font-lock-append-text-property lo hi 'face (if even 'num3-face-even 'num3-face-odd))) (provide 'num3) ;;; num3.el ends here ---------- >% ---------------------------------------------------------- -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 12:27 ` Michal Nazarewicz @ 2012-09-26 12:56 ` Noah Lavine 2012-09-26 13:06 ` Michal Nazarewicz 0 siblings, 1 reply; 20+ messages in thread From: Noah Lavine @ 2012-09-26 12:56 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: Felix Lee, Stefan Monnier, emacs-devel I don't usually post, but something confuses me about this patch (which otherwise looks awesome, by the way): in the doc string for num3-mode, you say `num3-face-even' face (which is empty by default) is the one used for the group closest to the decimal point. But looking at the faces, it appears that num3-face-odd is '((t)), and num3-face-even has lots of attributes. Am I misunderstanding the documentation, or did you switch the faces? Thanks for writing this. It looks great. Noah Lavine On Wed, Sep 26, 2012 at 8:27 AM, Michal Nazarewicz <mpn@google.com> wrote: > On Wed, Sep 26 2012, Stefan Monnier wrote: >> For single-file packages, you just need to file to be structured >> correctly (try C-u M-x checkdoc-current-buffer) and have "Version:" >> and "Maintainer:" headers at the beginning. > > Attached below. > > checkdoc-current-buffer gives me two errors but I'm not sure how to fix > those since in given instances num3-mode refers to the mode. > > num3.el:102: Disambiguate num3-mode by preceding w/ function,command,variable,option or symbol. > num3.el:111: Disambiguate num3-mode by preceding w/ function,command,variable,option or symbol. > >> Also the packages need to have their copyright paperwork in order, just >> like code included with Emacs, so we can easily move code between >> the two. > > Everything should be in order on that part. Google holds the Copyright, > but it has the proper paperwork done (I have contributed previously). > > ---------- >% ---------------------------------------------------------- > > ;;; num3-mode.el --- highlight groups of digits in long numbers -*- lexical-binding: t -*- > > ;; Copyright (C) 2012 Free Software Foundation, Inc. > > ;; Author: Felix Lee <felix8a@gmail.com>, Michal Nazarewicz <mina86@mina86.com> > ;; Maintainer: Michal Nazarewicz <mina86@mina86.com> > ;; Version: 1.0 > ;; Keywoards: faces, minor-mode > > ;; GNU Emacs is free software: you can redistribute it and/or modify > ;; it under the terms of the GNU General Public License as published by > ;; the Free Software Foundation, either version 3 of the License, or > ;; (at your option) any later version. > > ;; GNU Emacs is distributed in the hope that it will be useful, > ;; but WITHOUT ANY WARRANTY; without even the implied warranty of > ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > ;; GNU General Public License for more details. > > ;; You should have received a copy of the GNU General Public License > ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. > > ;;; Commentary: > > ;; Num3 is a minor mode that makes long numbers more readable by > ;; highlighting groups of 3 (customisable) decimal digits or 4 hex > ;; digits when font-lock is on. Highlighting alternates between two > ;; faces that can be customised. > > ;;; Usage: > > ;; M-x num3-mode toggle for current buffer. > ;; M-x global-num3-mode toggle for all buffers. > ;; > ;; Or add the following to your ~/.emacs file: > ;; (load "path/to/num3") > ;; (global-num3-mode) > > ;;; Code: > > (defgroup num3 nil > "Num3 is a minor mode that makes long numbers more readable by > highlighting groups of decimal digits or 4 hex digits when > font-lock is on." > :group 'text) > > (defcustom num3-group-size 3 > "Number of digits to group in decimal numbers.") > > (defcustom num3-threshold 5 > "Number must be at least that long to start highlighting.") > > (defface num3-face-odd > '((t)) > "Face to add for odd groups of digits." > :group 'num3) > > (defface num3-face-even > '((t :underline t :weight bold :background "#eeeeee")) > "Face to add for even groups of digits. > The default face uses redundant signaling, because this is in > addition to any other font-lock highlighting." > :group 'num3) > > ;;; Implementation: > > (require 'font-lock) > > ;;;###autoload > (define-minor-mode num3-mode > "Toggle num3 minor mode in the current buffer. > Num3 minor mode makes long numbers more readable by highlighting > groups of digits when font-lock mode is on. > > If a number is longer than `num3-threshold', the mode will split > it into a group of `num3-group-size' (if number is decimal) or > 4 (if number is hexadecimal) digits. Hexadecimal number is > detected as one starting with 0x, 0X or #. > > With decimal numbers, fractions are recognised as well and > grouped from the beginning rathar then from end. For instance, > with group size of 3, a number \"12345.12345\" will be split into > groups as follows: \"12|345.123|45\". Fractions without integer > part are also recognised, eg. \".12345\". > > The groups are highlighted alternately using `num3-face-odd' and > `num3-face-even' faces. `num3-face-even' face (which is empty by > default) is the one used for the group closest to the decimal point." > nil " num3" nil > (if num3-mode > (unless (assoc '-num3-matcher font-lock-keywords) > (font-lock-add-keywords nil '(-num3-matcher) 'append)) > (font-lock-remove-keywords nil '(-num3-matcher))) > (when font-lock-mode > (font-lock-fontify-buffer))) > > ;;;###autoload > (define-globalized-minor-mode global-num3-mode num3-mode turn-on-num3-mode) > > ;;;###autoload > (defun turn-on-num3-mode () > "Turn `num3-mode' on if it's not enabled." > (unless num3-mode (num3-mode t))) > > (defconst -num3-number-re > (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal > "\\|\\([0-9]+\\)" ; 2 = decimal > "\\|\\.\\([0-9]+\\)")) ; 3 = fraction > > (defun -num3-matcher (lim) > "Function used as a font-lock-keywoard handler used in `num3-mode'. > Performs fontification of numbers from point to LIM." > (save-excursion > (while (re-search-forward -num3-number-re lim t) > (-num3-int (match-beginning 1) (match-end 1) 4) > (-num3-int (match-beginning 2) (match-end 2) num3-group-size) > (-num3-frac (match-beginning 3) (match-end 3) num3-group-size))) > nil) > > (defun -num3-int (lo hi n) > "Highlight groups of digits in a long number. > LO and HI arguments specify the range where the number is > located. If the length of that region exceeds `num3-threshold', > the function will split it into groups of N digits and fontify > tham alternately using `num3-face-odd' and `num3-face-even' > faces. Grouping is done from the end, eg. (12)(345)." > (when (and lo (>= (- hi lo) num3-threshold)) > (let (even) > (while (< lo hi) > (-num3-put even (max lo (- hi n)) hi) > (setq hi (- hi n) even (not even)))))) > > (defun -num3-frac (lo hi n) > "Highlight groups of digits in a long number. > LO and HI arguments specify the range where the number is > located. If the length of that region exceeds `num3-threshold', > the function will split it into groups of N digits and fontify > tham alternately using `num3-face-odd' and `num3-face-even' > faces. Grouping is done from the beginning, eg. (123)(45)." > (when (and lo (>= (- hi lo) num3-threshold)) > (let (even) > (while (< lo hi) > (-num3-put even lo (min hi (+ lo n))) > (setq lo (+ lo n) even (not even)))))) > > (defun -num3-put (even lo hi) > "Add font lock text property to highlight a single group of digit. > Use `num3-face-odd' if EVEN is nil and `num3-face-even' if EVEN is > non-nil. The region the face is set to is from LO to HI." > (font-lock-append-text-property lo hi 'face > (if even 'num3-face-even 'num3-face-odd))) > > (provide 'num3) > > ;;; num3.el ends here > > ---------- >% ---------------------------------------------------------- > > -- > Best regards, _ _ > .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o > ..o | Computer Science, Michał “mina86” Nazarewicz (o o) > ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- > > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 12:56 ` Noah Lavine @ 2012-09-26 13:06 ` Michal Nazarewicz 2012-09-26 14:58 ` Lennart Borgman 2012-09-26 20:01 ` Stefan Monnier 0 siblings, 2 replies; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-26 13:06 UTC (permalink / raw) To: Noah Lavine; +Cc: Felix Lee, Stefan Monnier, emacs-devel [-- Attachment #1: Type: text/plain, Size: 6990 bytes --] On Wed, Sep 26 2012, Noah Lavine wrote: > I don't usually post, but something confuses me about this patch > (which otherwise looks awesome, by the way): > > in the doc string for num3-mode, you say > > `num3-face-even' face (which is empty by > default) is the one used for the group closest to the decimal point. > > But looking at the faces, it appears that num3-face-odd is '((t)), and > num3-face-even has lots of attributes. Am I misunderstanding the > documentation, or did you switch the faces? Sorry, you're absolutely right. It's mistake in documentation in my part. Attached is fixed version of the file. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- ---------- >% ---------------------------------------------------------- ;;; num3-mode.el --- highlight groups of digits in long numbers -*- lexical-binding: t -*- ;; Copyright (C) 2012 Free Software Foundation, Inc. ;; Author: Felix Lee <felix8a@gmail.com>, Michal Nazarewicz <mina86@mina86.com> ;; Maintainer: Michal Nazarewicz <mina86@mina86.com> ;; Keywoards: faces, minor-mode ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: ;; Num3 is a minor mode that makes long numbers more readable by ;; highlighting groups of 3 (customisable) decimal digits or 4 hex ;; digits when font-lock is on. Highlighting alternates between two ;; faces that can be customised. ;;; Usage: ;; M-x num3-mode toggle for current buffer. ;; M-x global-num3-mode toggle for all buffers. ;; ;; Or add the following to your ~/.emacs file: ;; (load "path/to/num3") ;; (global-num3-mode) ;;; Code: (defgroup num3 nil "Num3 is a minor mode that makes long numbers more readable by highlighting groups of decimal digits or 4 hex digits when font-lock is on." :group 'text) (defcustom num3-group-size 3 "Number of digits to group in decimal numbers.") (defcustom num3-threshold 5 "Number must be at least that long to start highlighting.") (defface num3-face-odd '((t)) "Face to add for odd groups of digits." :group 'num3) (defface num3-face-even '((t :underline t :weight bold :background "#eeeeee")) "Face to add for even groups of digits. The default face uses redundant signaling, because this is in addition to any other font-lock highlighting." :group 'num3) ;;; Implementation: (require 'font-lock) ;;;###autoload (define-minor-mode num3-mode "Toggle num3 minor mode in the current buffer. Num3 minor mode makes long numbers more readable by highlighting groups of digits when font-lock mode is on. If a number is longer than `num3-threshold', the mode will split it into a group of `num3-group-size' (if number is decimal) or 4 (if number is hexadecimal) digits. Hexadecimal number is detected as one starting with 0x, 0X or #. With decimal numbers, fractions are recognised as well and grouped from the beginning rathar then from end. For instance, with group size of 3, a number \"12345.12345\" will be split into groups as follows: \"12|345.123|45\". Fractions without integer part are also recognised, eg. \".12345\". The groups are highlighted alternately using `num3-face-odd' and `num3-face-even' faces. `num3-face-odd' face (which is empty by default) is the one used for the group closest to the decimal point, ie. groups are counted starting with one outwards from the (place where) decimal point (would be) is." nil " num3" nil (if num3-mode (unless (assoc '-num3-matcher font-lock-keywords) (font-lock-add-keywords nil '(-num3-matcher) 'append)) (font-lock-remove-keywords nil '(-num3-matcher))) (when font-lock-mode (font-lock-fontify-buffer))) ;;;###autoload (define-globalized-minor-mode global-num3-mode num3-mode turn-on-num3-mode) ;;;###autoload (defun turn-on-num3-mode () "Turn `num3-mode' on if it's not enabled." (unless num3-mode (num3-mode t))) (defconst -num3-number-re (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal "\\|\\([0-9]+\\)" ; 2 = decimal "\\|\\.\\([0-9]+\\)")) ; 3 = fraction (defun -num3-matcher (lim) "Function used as a font-lock-keywoard handler used in `num3-mode'. Performs fontification of numbers from point to LIM." (save-excursion (while (re-search-forward -num3-number-re lim t) (-num3-int (match-beginning 1) (match-end 1) 4) (-num3-int (match-beginning 2) (match-end 2) num3-group-size) (-num3-frac (match-beginning 3) (match-end 3) num3-group-size))) nil) (defun -num3-int (lo hi n) "Highlight groups of digits in a long number. LO and HI arguments specify the range where the number is located. If the length of that region exceeds `num3-threshold', the function will split it into groups of N digits and fontify tham alternately using `num3-face-odd' and `num3-face-even' faces. Grouping is done from the end, eg. (12)(345)." (when (and lo (>= (- hi lo) num3-threshold)) (let (even) (while (< lo hi) (-num3-put even (max lo (- hi n)) hi) (setq hi (- hi n) even (not even)))))) (defun -num3-frac (lo hi n) "Highlight groups of digits in a long number. LO and HI arguments specify the range where the number is located. If the length of that region exceeds `num3-threshold', the function will split it into groups of N digits and fontify tham alternately using `num3-face-odd' and `num3-face-even' faces. Grouping is done from the beginning, eg. (123)(45)." (when (and lo (>= (- hi lo) num3-threshold)) (let (even) (while (< lo hi) (-num3-put even lo (min hi (+ lo n))) (setq lo (+ lo n) even (not even)))))) (defun -num3-put (even lo hi) "Add font lock text property to highlight a single group of digit. Use `num3-face-odd' if EVEN is nil and `num3-face-even' if EVEN is non-nil. The region the face is set to is from LO to HI." (font-lock-append-text-property lo hi 'face (if even 'num3-face-even 'num3-face-odd))) (provide 'num3) ;;; num3.el ends here [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 13:06 ` Michal Nazarewicz @ 2012-09-26 14:58 ` Lennart Borgman 2012-09-26 20:02 ` Stefan Monnier 2012-09-26 20:01 ` Stefan Monnier 1 sibling, 1 reply; 20+ messages in thread From: Lennart Borgman @ 2012-09-26 14:58 UTC (permalink / raw) To: Michal Nazarewicz Cc: Felix Lee, Noah Lavine, Stefan Monnier, Emacs-Devel devel [-- Attachment #1: Type: text/plain, Size: 7534 bytes --] Just for your information: There is such a mode already in nXhtml. I called it ocr-users-mode since that I mostly use it for. On Sep 26, 2012 3:06 PM, "Michal Nazarewicz" <mpn@google.com> wrote: > On Wed, Sep 26 2012, Noah Lavine wrote: > > I don't usually post, but something confuses me about this patch > > (which otherwise looks awesome, by the way): > > > > in the doc string for num3-mode, you say > > > > `num3-face-even' face (which is empty by > > default) is the one used for the group closest to the decimal point. > > > > But looking at the faces, it appears that num3-face-odd is '((t)), and > > num3-face-even has lots of attributes. Am I misunderstanding the > > documentation, or did you switch the faces? > > Sorry, you're absolutely right. It's mistake in documentation in my > part. Attached is fixed version of the file. > > -- > Best regards, _ _ > .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o > ..o | Computer Science, Michał “mina86” Nazarewicz (o o) > ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- > > ---------- >% ---------------------------------------------------------- > > ;;; num3-mode.el --- highlight groups of digits in long numbers -*- > lexical-binding: t -*- > > ;; Copyright (C) 2012 Free Software Foundation, Inc. > > ;; Author: Felix Lee <felix8a@gmail.com>, Michal Nazarewicz < > mina86@mina86.com> > ;; Maintainer: Michal Nazarewicz <mina86@mina86.com> > ;; Keywoards: faces, minor-mode > > ;; GNU Emacs is free software: you can redistribute it and/or modify > ;; it under the terms of the GNU General Public License as published by > ;; the Free Software Foundation, either version 3 of the License, or > ;; (at your option) any later version. > > ;; GNU Emacs is distributed in the hope that it will be useful, > ;; but WITHOUT ANY WARRANTY; without even the implied warranty of > ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > ;; GNU General Public License for more details. > > ;; You should have received a copy of the GNU General Public License > ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. > > ;;; Commentary: > > ;; Num3 is a minor mode that makes long numbers more readable by > ;; highlighting groups of 3 (customisable) decimal digits or 4 hex > ;; digits when font-lock is on. Highlighting alternates between two > ;; faces that can be customised. > > ;;; Usage: > > ;; M-x num3-mode toggle for current buffer. > ;; M-x global-num3-mode toggle for all buffers. > ;; > ;; Or add the following to your ~/.emacs file: > ;; (load "path/to/num3") > ;; (global-num3-mode) > > ;;; Code: > > (defgroup num3 nil > "Num3 is a minor mode that makes long numbers more readable by > highlighting groups of decimal digits or 4 hex digits when > font-lock is on." > :group 'text) > > (defcustom num3-group-size 3 > "Number of digits to group in decimal numbers.") > > (defcustom num3-threshold 5 > "Number must be at least that long to start highlighting.") > > (defface num3-face-odd > '((t)) > "Face to add for odd groups of digits." > :group 'num3) > > (defface num3-face-even > '((t :underline t :weight bold :background "#eeeeee")) > "Face to add for even groups of digits. > The default face uses redundant signaling, because this is in > addition to any other font-lock highlighting." > :group 'num3) > > ;;; Implementation: > > (require 'font-lock) > > ;;;###autoload > (define-minor-mode num3-mode > "Toggle num3 minor mode in the current buffer. > Num3 minor mode makes long numbers more readable by highlighting > groups of digits when font-lock mode is on. > > If a number is longer than `num3-threshold', the mode will split > it into a group of `num3-group-size' (if number is decimal) or > 4 (if number is hexadecimal) digits. Hexadecimal number is > detected as one starting with 0x, 0X or #. > > With decimal numbers, fractions are recognised as well and > grouped from the beginning rathar then from end. For instance, > with group size of 3, a number \"12345.12345\" will be split into > groups as follows: \"12|345.123|45\". Fractions without integer > part are also recognised, eg. \".12345\". > > The groups are highlighted alternately using `num3-face-odd' and > `num3-face-even' faces. `num3-face-odd' face (which is empty by > default) is the one used for the group closest to the decimal point, > ie. groups are counted starting with one outwards from the (place > where) decimal point (would be) is." > nil " num3" nil > (if num3-mode > (unless (assoc '-num3-matcher font-lock-keywords) > (font-lock-add-keywords nil '(-num3-matcher) 'append)) > (font-lock-remove-keywords nil '(-num3-matcher))) > (when font-lock-mode > (font-lock-fontify-buffer))) > > ;;;###autoload > (define-globalized-minor-mode global-num3-mode num3-mode turn-on-num3-mode) > > ;;;###autoload > (defun turn-on-num3-mode () > "Turn `num3-mode' on if it's not enabled." > (unless num3-mode (num3-mode t))) > > (defconst -num3-number-re > (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal > "\\|\\([0-9]+\\)" ; 2 = decimal > "\\|\\.\\([0-9]+\\)")) ; 3 = fraction > > (defun -num3-matcher (lim) > "Function used as a font-lock-keywoard handler used in `num3-mode'. > Performs fontification of numbers from point to LIM." > (save-excursion > (while (re-search-forward -num3-number-re lim t) > (-num3-int (match-beginning 1) (match-end 1) 4) > (-num3-int (match-beginning 2) (match-end 2) num3-group-size) > (-num3-frac (match-beginning 3) (match-end 3) num3-group-size))) > nil) > > (defun -num3-int (lo hi n) > "Highlight groups of digits in a long number. > LO and HI arguments specify the range where the number is > located. If the length of that region exceeds `num3-threshold', > the function will split it into groups of N digits and fontify > tham alternately using `num3-face-odd' and `num3-face-even' > faces. Grouping is done from the end, eg. (12)(345)." > (when (and lo (>= (- hi lo) num3-threshold)) > (let (even) > (while (< lo hi) > (-num3-put even (max lo (- hi n)) hi) > (setq hi (- hi n) even (not even)))))) > > (defun -num3-frac (lo hi n) > "Highlight groups of digits in a long number. > LO and HI arguments specify the range where the number is > located. If the length of that region exceeds `num3-threshold', > the function will split it into groups of N digits and fontify > tham alternately using `num3-face-odd' and `num3-face-even' > faces. Grouping is done from the beginning, eg. (123)(45)." > (when (and lo (>= (- hi lo) num3-threshold)) > (let (even) > (while (< lo hi) > (-num3-put even lo (min hi (+ lo n))) > (setq lo (+ lo n) even (not even)))))) > > (defun -num3-put (even lo hi) > "Add font lock text property to highlight a single group of digit. > Use `num3-face-odd' if EVEN is nil and `num3-face-even' if EVEN is > non-nil. The region the face is set to is from LO to HI." > (font-lock-append-text-property lo hi 'face > (if even 'num3-face-even > 'num3-face-odd))) > > (provide 'num3) > > ;;; num3.el ends here > > > [-- Attachment #2: Type: text/html, Size: 8965 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 14:58 ` Lennart Borgman @ 2012-09-26 20:02 ` Stefan Monnier 0 siblings, 0 replies; 20+ messages in thread From: Stefan Monnier @ 2012-09-26 20:02 UTC (permalink / raw) To: Lennart Borgman Cc: Felix Lee, Noah Lavine, Michal Nazarewicz, Emacs-Devel devel > Just for your information: There is such a mode already in nXhtml. Reminds me: I'm still waiting for your submission of mumamo and nxhtml for inclusion in GNU ELPA. Stefan ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 13:06 ` Michal Nazarewicz 2012-09-26 14:58 ` Lennart Borgman @ 2012-09-26 20:01 ` Stefan Monnier 2012-09-26 21:33 ` Michal Nazarewicz ` (2 more replies) 1 sibling, 3 replies; 20+ messages in thread From: Stefan Monnier @ 2012-09-26 20:01 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: Noah Lavine, emacs-devel, Felix Lee > Sorry, you're absolutely right. It's mistake in documentation in my > part. Attached is fixed version of the file. Thanks, I just added it to the `elpa' so it should appear in GNU ELPA next time someone refreshes it. I made the following changes: - Added a "Version: 1.0" header. - Removed the (require 'font-lock) that seemed unnecessary. - Removed turn-on-num3-mode since (num3-mode) does the same anyway. I do see that when num3-mode is already enabled (turn-on-num3-mode) did nothing whereas (num3-mode) will call font-lock-fontify-buffer but if that's a problem, we should fix num3-mode. I'm not sure what the "-num-" prefix is meant to be and I'm not fond of it. If it's meant for internal functions, then please use "num--" instead. > checkdoc-current-buffer gives me two errors but I'm not sure how to fix > those since in given instances num3-mode refers to the mode. Don't take checkdoc for the gospel; those "errors" are fine. If you do want to fix them, do as told: add the word "function" or "command" soon before the offending `num3-mode'. If you want to maintain the file directly in the elpa branch (rather than send us patches), then please ask for write access (by registering an account on savannah, and asking for membership in the "emacs" group from that account). Thank you for your contribution, Stefan ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 20:01 ` Stefan Monnier @ 2012-09-26 21:33 ` Michal Nazarewicz 2012-09-26 21:44 ` Stefan Monnier 2012-09-26 21:36 ` turn-on/off-*MODE* (was: Re: PATCH: num3-mode for highlighting groups of digits in long numbers) chad 2012-09-26 21:59 ` PATCH: num3-mode for highlighting groups of digits in long numbers felix 2 siblings, 1 reply; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-26 21:33 UTC (permalink / raw) To: Stefan Monnier; +Cc: Noah Lavine, emacs-devel, Felix Lee [-- Attachment #1: Type: text/plain, Size: 2048 bytes --] On Wed, Sep 26 2012, Stefan Monnier wrote: >> Sorry, you're absolutely right. It's mistake in documentation in my >> part. Attached is fixed version of the file. > > Thanks, I just added it to the `elpa' so it should appear in GNU ELPA > next time someone refreshes it. > > I made the following changes: > - Added a "Version: 1.0" header. Ah, thanks. I've added the header at one point but must have removed it by mistake during subsequent edits. > - Removed the (require 'font-lock) that seemed unnecessary. Well, num3 does use some font-lock-* functions, but they may be autoloads or something. > - Removed turn-on-num3-mode since (num3-mode) does the same anyway. > I do see that when num3-mode is already enabled (turn-on-num3-mode) did > nothing whereas (num3-mode) will call font-lock-fontify-buffer but if > that's a problem, we should fix num3-mode. Uh? num3-mode properly toggles number highlighting for me. > I'm not sure what the "-num-" prefix is meant to be and I'm not fond > of it. If it's meant for internal functions, then please use > "num--" instead. Will do. >> checkdoc-current-buffer gives me two errors but I'm not sure how to fix >> those since in given instances num3-mode refers to the mode. > > Don't take checkdoc for the gospel; those "errors" are fine. > If you do want to fix them, do as told: add the word "function" or > "command" soon before the offending `num3-mode'. Yeah, I've decided that in this instance, I'm smarter than > If you want to maintain the file directly in the elpa branch (rather > than send us patches), then please ask for write access (by registering > an account on savannah, and asking for membership in the "emacs" group > from that account). Will do. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 21:33 ` Michal Nazarewicz @ 2012-09-26 21:44 ` Stefan Monnier 2012-09-26 23:33 ` Michal Nazarewicz 0 siblings, 1 reply; 20+ messages in thread From: Stefan Monnier @ 2012-09-26 21:44 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: Noah Lavine, emacs-devel, Felix Lee > Uh? num3-mode properly toggles number highlighting for me. Only if you compile it with Emacs<23 or if you're confusing interactive calls and Lisp calls (I'm talking about a Lisp call of the form (num3-mode); M-x num3-mode RET will indeed toggle). Stefan ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 21:44 ` Stefan Monnier @ 2012-09-26 23:33 ` Michal Nazarewicz 0 siblings, 0 replies; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-26 23:33 UTC (permalink / raw) To: Stefan Monnier; +Cc: Noah Lavine, emacs-devel, Felix Lee [-- Attachment #1: Type: text/plain, Size: 614 bytes --] On Wed, Sep 26 2012, Stefan Monnier wrote: >> Uh? num3-mode properly toggles number highlighting for me. > > Only if you compile it with Emacs<23 or if you're confusing interactive > calls and Lisp calls (I'm talking about a Lisp call of the form (num3-mode); > M-x num3-mode RET will indeed toggle). Ah, makes sense, I guess. Thanks. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* turn-on/off-*MODE* (was: Re: PATCH: num3-mode for highlighting groups of digits in long numbers) 2012-09-26 20:01 ` Stefan Monnier 2012-09-26 21:33 ` Michal Nazarewicz @ 2012-09-26 21:36 ` chad 2012-09-26 21:47 ` turn-on/off-*MODE* Stefan Monnier 2012-09-26 21:59 ` PATCH: num3-mode for highlighting groups of digits in long numbers felix 2 siblings, 1 reply; 20+ messages in thread From: chad @ 2012-09-26 21:36 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel On 26 Sep 2012, at 13:01, Stefan Monnier <monnier@iro.umontreal.ca> wrote: > - Removed turn-on-num3-mode since (num3-mode) does the same anyway. > I do see that when num3-mode is already enabled (turn-on-num3-mode) did > nothing whereas (num3-mode) will call font-lock-fontify-buffer but if > that's a problem, we should fix num3-mode. Is there a general guideline for when to add or not add these? I find them generally useful for hooks I've been running with the following small patch to hl-line.el for several months, following the pattern in autofill and flyspell. Thanks, *Chad *** 155,160 **** --- 155,174 ---- (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t) (remove-hook 'pre-command-hook #'hl-line-unhighlight t))) + + ;;;###autoload + (defun turn-on-hl-line () + "Unconditionally turn on highlight-line mode." + (hl-line-mode 1)) + + ;;;###autoload + (defun turn-off-hl-line () + "Unconditionally turn off highlight-line mode." + (hl-line-mode -1)) + + (custom-add-option 'dired-mode-hook 'turn-on-hl-line) + + (defun hl-line-highlight () "Activate the Hl-Line overlay on the current line." (if hl-line-mode ; Might be changed outside the mode function. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: turn-on/off-*MODE* 2012-09-26 21:36 ` turn-on/off-*MODE* (was: Re: PATCH: num3-mode for highlighting groups of digits in long numbers) chad @ 2012-09-26 21:47 ` Stefan Monnier 0 siblings, 0 replies; 20+ messages in thread From: Stefan Monnier @ 2012-09-26 21:47 UTC (permalink / raw) To: chad; +Cc: emacs-devel > Is there a general guideline for when to add or not add these? Yes: never add them. > + ;;;###autoload > + (defun turn-on-hl-line () > + "Unconditionally turn on highlight-line mode." > + (hl-line-mode 1)) (hl-line-mode) is the same as (hl-line-mode 1), so you can rewrite is as: ;;;###autoload (defun turn-on-hl-line () "Unconditionally turn on highlight-line mode." (hl-line-mode)) => ;;;###autoload (defalias 'turn-on-hl-line #'hl-line-mode "Unconditionally turn on highlight-line mode.") at which point you can decide it's not worth the trouble. > + ;;;###autoload > + (defun turn-off-hl-line () > + "Unconditionally turn off highlight-line mode." > + (hl-line-mode -1)) I've virtually never seen it used. So for the very rare cases (lambda () (foo-mode -1)) works just as well and isn't that much longer #'turn-off-foo-mode. Stefan ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-26 20:01 ` Stefan Monnier 2012-09-26 21:33 ` Michal Nazarewicz 2012-09-26 21:36 ` turn-on/off-*MODE* (was: Re: PATCH: num3-mode for highlighting groups of digits in long numbers) chad @ 2012-09-26 21:59 ` felix 2 siblings, 0 replies; 20+ messages in thread From: felix @ 2012-09-26 21:59 UTC (permalink / raw) To: Stefan Monnier; +Cc: Noah Lavine, Michal Nazarewicz, emacs-devel [-- Attachment #1: Type: text/plain, Size: 839 bytes --] On Wed, Sep 26, 2012 at 1:01 PM, Stefan Monnier <monnier@iro.umontreal.ca>wrote: > - Removed turn-on-num3-mode since (num3-mode) does the same anyway. > I do see that when num3-mode is already enabled (turn-on-num3-mode) did > nothing whereas (num3-mode) will call font-lock-fontify-buffer but if > that's a problem, we should fix num3-mode. > the turn-on- thing is a convention from emacs 23 and earlier. yeah, looks like it should go away, and the logic of calling (num3-mode) from lisp might need to be fixed > I'm not sure what the "-num-" prefix is meant to be and I'm not fond > of it. If it's meant for internal functions, then please use > "num--" instead. > yeah that's my fault, I've been flipping back and forth between using -pkg- and pkg--, and at the time I wrote num3 I was using -pkg-, and I prefer pkg-- now. [-- Attachment #2: Type: text/html, Size: 1337 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-06 16:21 PATCH: num3-mode for highlighting groups of digits in long numbers Michal Nazarewicz 2012-09-06 17:23 ` Lars Ingebrigtsen 2012-09-06 21:22 ` Stefan Monnier @ 2012-09-06 23:18 ` Jambunathan K 2012-09-06 23:41 ` felix 2012-09-07 1:14 ` Michal Nazarewicz 2 siblings, 2 replies; 20+ messages in thread From: Jambunathan K @ 2012-09-06 23:18 UTC (permalink / raw) To: Michal Nazarewicz; +Cc: Felix Lee, emacs-devel > Hello everyone, > > This time I bring to you a patch adding num3-mode which helps read long > numbers by alternating highlighting of group of digits in a long > number, so for instance something like: > > 12345678.12345678 > > would be displayed as ("-" symbolising underscore): > > 12345678.12345678 > --- --- > > This also works for hexadecimal numbers by grouping 4-digits at a time, > ie.: > > 0x0123456789ABCDEF > ---- ---- Just curious. Can we highlight like telephone numbers by creating an *extra* dash, space or a point. Tel no: 1234567890 rendered as Tel no: 12345-67890 In some ways, the highlighting as seen above is in-band and not out-of-band (as underlines are). It is also naturally how one would write down long numbers on a piece of paper for ease of reading. -- ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-06 23:18 ` Jambunathan K @ 2012-09-06 23:41 ` felix 2012-09-07 1:14 ` Michal Nazarewicz 1 sibling, 0 replies; 20+ messages in thread From: felix @ 2012-09-06 23:41 UTC (permalink / raw) To: Jambunathan K; +Cc: Michal Nazarewicz, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1586 bytes --] On Thu, Sep 6, 2012 at 4:18 PM, Jambunathan K <kjambunathan@gmail.com>wrote: > > > Hello everyone, > > > > This time I bring to you a patch adding num3-mode which helps read long > > numbers by alternating highlighting of group of digits in a long > > number, so for instance something like: > > > > 12345678.12345678 > > > > would be displayed as ("-" symbolising underscore): > > > > 12345678.12345678 > > --- --- > > > > This also works for hexadecimal numbers by grouping 4-digits at a time, > > ie.: > > > > 0x0123456789ABCDEF > > ---- ---- > > Just curious. > > Can we highlight like telephone numbers by creating an *extra* dash, > space or a point. > > Tel no: 1234567890 rendered as > Tel no: 12345-67890 > > In some ways, the highlighting as seen above is in-band and not > out-of-band (as underlines are). It is also naturally how one would > write down long numbers on a piece of paper for ease of reading. > That would throw off alignment of things like monospace-formatted tables. Even if columns in a table are separated with tabs, adding extra chars in the rendering can mess up the alignment. One alternative is to tweak interletter spacing so that groups of digits are bunched together, so that there's a noticeable gap between groups, but the digits still occupy the same width they normally would. I think this would be hard to do reliably in current emacs. I don't see any way to reduce interletter spacing other than using a smaller font, and there doesn't seem to be a way to compute the pixel width of text either. [-- Attachment #2: Type: text/html, Size: 2072 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: PATCH: num3-mode for highlighting groups of digits in long numbers 2012-09-06 23:18 ` Jambunathan K 2012-09-06 23:41 ` felix @ 2012-09-07 1:14 ` Michal Nazarewicz 1 sibling, 0 replies; 20+ messages in thread From: Michal Nazarewicz @ 2012-09-07 1:14 UTC (permalink / raw) To: Jambunathan K; +Cc: Felix Lee, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1995 bytes --] >> This time I bring to you a patch adding num3-mode which helps read long >> numbers by alternating highlighting of group of digits in a long >> number, so for instance something like: >> >> 12345678.12345678 >> >> would be displayed as ("-" symbolising underscore): >> >> 12345678.12345678 >> --- --- >> >> This also works for hexadecimal numbers by grouping 4-digits at a time, >> ie.: >> >> 0x0123456789ABCDEF >> ---- ---- On Fri, Sep 07 2012, Jambunathan K wrote: > Just curious. > > Can we highlight like telephone numbers by creating an *extra* dash, > space or a point. > > Tel no: 1234567890 rendered as > Tel no: 12345-67890 If you ask whether it is theoretically possible than it is. nxml-mode has code to render entities, so the same mechanism can be used to add dashes to separate numbers. Still, this is not doable with num3-mode at this point. Feel free to hack support for it. :) It should not be too hard -- just need to add some defcustom variable and than modify -num3-put defun. Note that this will work for any kind of *numbers*, so if you want to treat some specific kind of numbers specially, like phone numbers, than there will be more coding, probably including a different regex for phone number detection (BTW. good luck with that, I've spent weeks on my previous work doing something like that for Mozilla). In general however, I see more problems with adding extra dashes than uses. > In some ways, the highlighting as seen above is in-band and not > out-of-band (as underlines are). It is also naturally how one would > write down long numbers on a piece of paper for ease of reading. I don't quite get your point here. -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo-- [-- Attachment #2.1: Type: text/plain, Size: 0 bytes --] [-- Attachment #2.2: Type: application/pgp-signature, Size: 835 bytes --] ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2012-09-26 23:33 UTC | newest] Thread overview: 20+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-09-06 16:21 PATCH: num3-mode for highlighting groups of digits in long numbers Michal Nazarewicz 2012-09-06 17:23 ` Lars Ingebrigtsen 2012-09-06 21:22 ` Stefan Monnier 2012-09-25 20:40 ` Michal Nazarewicz 2012-09-26 1:07 ` Stefan Monnier 2012-09-26 12:27 ` Michal Nazarewicz 2012-09-26 12:56 ` Noah Lavine 2012-09-26 13:06 ` Michal Nazarewicz 2012-09-26 14:58 ` Lennart Borgman 2012-09-26 20:02 ` Stefan Monnier 2012-09-26 20:01 ` Stefan Monnier 2012-09-26 21:33 ` Michal Nazarewicz 2012-09-26 21:44 ` Stefan Monnier 2012-09-26 23:33 ` Michal Nazarewicz 2012-09-26 21:36 ` turn-on/off-*MODE* (was: Re: PATCH: num3-mode for highlighting groups of digits in long numbers) chad 2012-09-26 21:47 ` turn-on/off-*MODE* Stefan Monnier 2012-09-26 21:59 ` PATCH: num3-mode for highlighting groups of digits in long numbers felix 2012-09-06 23:18 ` Jambunathan K 2012-09-06 23:41 ` felix 2012-09-07 1:14 ` Michal Nazarewicz
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.