bug-recutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Align keybindings with conventions, deprecate unused code


From: Antoine Kalmbach
Subject: [PATCH] Align keybindings with conventions, deprecate unused code
Date: Fri, 13 Nov 2020 10:20:04 +0200

* rec-mode.el: Add Author/Maintainer/URL package headers.
Set version to 1.6.
(rec-types): Make defconst.
(rec-check-type): Remove. recfix can handle all this.
(rec-parse-type): Add missing rec-type ctor call.
Add comment about future deprecation.
(rec-mode-map): Use (kbd ...) instead of raw sequences (easier to
read). Remove `rec-cmd-jump' (nonexistent binding).
(rec-cmd-edit-field-message): Add.
(rec-cmd-edit-field): Use substitute-command-keys to print the
binding to `rec-finish-editing' and `rec-finish-editing-field'.
(rec-edit-record): Ditto.
(rec-edit-type): Ditto.
(rec-edit-buffer): Ditto.
(rec-mode-edit-map): Change keybindings to start with `C-c' and a
with a control character, `C-c c' becomes `C-c C-c'. Established
Emacs keybinding conventions reserve `C-c <letter>' for users to
define their own shortcuts, so major modes ought to stay out of
them. This will probably be somewhat jarring for users used to the
existing bindings, but it's less worse than violating conventions.
See Info node `(elisp)Key Binding Conventions' for more information.

* rec-mode.texi (Edition modes): Note the changes in key bindings.
---
 rec-mode.el   | 166 +++++++++++++++++++-------------------------------
 rec-mode.info |  59 +++++++++---------
 rec-mode.texi |  12 ++--
 3 files changed, 102 insertions(+), 135 deletions(-)

diff --git a/rec-mode.el b/rec-mode.el
index fb6dacb..823506a 100644
--- a/rec-mode.el
+++ b/rec-mode.el
@@ -2,9 +2,11 @@
 
 ;; Copyright (C) 2009-2020  Free Software Foundation, Inc.
 
-;; Maintainer: Jose E. Marchesi <jose.marchesi@oracle.com>
+;; Author: Jose E. Marchesi <jose.marchesi@oracle.com>
+;; Maintainer: Antoine Kalmbach <ane@iki.fi>
+;; URL: https://www.gnu.org/software/recutils/
 ;; Package-Requires: ((emacs "25"))
-;; Version: 0
+;; Version: 1.6
 
 ;; This file is NOT part of GNU Emacs.
 
@@ -175,60 +177,59 @@ The default is t."
 
 (defvar rec-mode-edit-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "\C-cn" 'rec-cmd-goto-next-rec)
-    (define-key map "\C-cp" 'rec-cmd-goto-previous-rec)
-    (define-key map "\C-ce" 'rec-cmd-edit-field)
-    (define-key map "\C-cd" 'rec-cmd-show-descriptor)
-    (define-key map "\C-ct" 'rec-cmd-show-type)
-    (define-key map "\C-c#" 'rec-cmd-count)
-    (define-key map "\C-cm" 'rec-cmd-trim-field-value)
-    (define-key map "\C-cc" 'rec-cmd-compile)
-    (define-key map "\C-csq" 'rec-cmd-select-fast)
-    (define-key map "\C-css" 'rec-cmd-select-sex)
-    (define-key map "\C-ch" 'rec-cmd-show-summary)
-    (define-key map "\C-cI" 'rec-cmd-show-info)
-    (define-key map "\C-cf\C-w" 'rec-cmd-kill-field)
-    (define-key map "\C-cf\M-w" 'rec-cmd-copy-field)
-    (define-key map "\C-cr\C-w" 'rec-cmd-kill-record)
-    (define-key map "\C-cr\M-w" 'rec-cmd-copy-record)
+    (define-key map (kbd "C-c C-n") 'rec-cmd-goto-next-rec)
+    (define-key map (kbd "C-c C-p") 'rec-cmd-goto-previous-rec)
+    (define-key map (kbd "C-c C-e") 'rec-cmd-edit-field)
+    (define-key map (kbd "C-c C-d") 'rec-cmd-show-descriptor)
+    (define-key map (kbd "C-c C-t") 'rec-cmd-show-type)
+    (define-key map (kbd "C-c C-#") 'rec-cmd-count)
+    (define-key map (kbd "C-c C-%") 'rec-cmd-statistic)
+    (define-key map (kbd "C-c C-f m") 'rec-cmd-trim-field-value)
+    (define-key map (kbd "C-c C-k") 'rec-cmd-compile)
+    (define-key map (kbd "C-c C-s q") 'rec-cmd-select-fast)
+    (define-key map (kbd "C-c C-s s") 'rec-cmd-select-sex)
+    (define-key map (kbd "C-c M-h") 'rec-cmd-show-summary)
+    (define-key map (kbd "C-c C-i") 'rec-cmd-show-info)
+    (define-key map (kbd "C-c C-f C-w") 'rec-cmd-kill-field)
+    (define-key map (kbd "C-c C-f M-w") 'rec-cmd-copy-field)
+    (define-key map (kbd "C-c C-r C-w") 'rec-cmd-kill-record)
+    (define-key map (kbd "C-c C-r M-w") 'rec-cmd-copy-record)
+    (define-key map [tab] 'rec-cmd-goto-next-field)
     (define-key map (kbd "TAB") 'rec-cmd-goto-next-field)
-    (define-key map "\C-cb" 'rec-cmd-jump-back)
-    (define-key map "\C-c\C-c" 'rec-finish-editing)
+    (define-key map (kbd "C-c C-b") 'rec-cmd-jump-back)
+    (define-key map (kbd "C-c C-c") 'rec-finish-editing)
     map)
-  "Keymap for `rec-mode'.")
+  "Keymap for `rec-mode' when editing records.")
 
 (defvar rec-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "n" 'rec-cmd-goto-next-rec)
-    (define-key map "p" 'rec-cmd-goto-previous-rec)
-    (define-key map "e" 'rec-cmd-edit-field)
-    (define-key map "R" 'rec-edit-record)
-    (define-key map "T" 'rec-edit-type)
-    (define-key map "B" 'rec-edit-buffer)
-    (define-key map "A" 'rec-cmd-append-field)
-    (define-key map "I" 'rec-cmd-show-info)
-    (define-key map "d" 'rec-cmd-show-descriptor)
-    (define-key map "t" 'rec-cmd-show-type)
-    (define-key map "m" 'rec-cmd-trim-field-value)
-    (define-key map "c" 'rec-cmd-compile)
-    (define-key map "f\C-w" 'rec-cmd-kill-field)
-    (define-key map "f\M-w" 'rec-cmd-copy-field)
-    (define-key map "r\C-w" 'rec-cmd-kill-record)
-    (define-key map "r\M-w" 'rec-cmd-copy-record)
-    (define-key map "f\C-w" 'rec-cmd-kill-field)
-    (define-key map "f\M-w" 'rec-cmd-copy-field)
-    (define-key map "sq" 'rec-cmd-select-fast)
-    (define-key map "ss" 'rec-cmd-select-sex)
-    (define-key map "h" 'rec-cmd-show-summary)
-    (define-key map "\C-ct" 'rec-find-type)
-;;    (define-key map [remap move-beginning-of-line] 
'rec-cmd-beginning-of-line)
+    (define-key map (kbd "n") 'rec-cmd-goto-next-rec)
+    (define-key map (kbd "p") 'rec-cmd-goto-previous-rec)
+    (define-key map (kbd "e") 'rec-cmd-edit-field)
+    (define-key map (kbd "R") 'rec-edit-record)
+    (define-key map (kbd "T") 'rec-edit-type)
+    (define-key map (kbd "B") 'rec-edit-buffer)
+    (define-key map (kbd "A") 'rec-cmd-append-field)
+    (define-key map (kbd "I") 'rec-cmd-show-info)
+    (define-key map (kbd "d") 'rec-cmd-show-descriptor)
+    (define-key map (kbd "t") 'rec-cmd-show-type)
+    (define-key map (kbd "m") 'rec-cmd-trim-field-value)
+    (define-key map (kbd "c") 'rec-cmd-compile)
+    (define-key map (kbd "f C-w") 'rec-cmd-kill-field)
+    (define-key map (kbd "f M-w") 'rec-cmd-copy-field)
+    (define-key map (kbd "r C-w") 'rec-cmd-kill-record)
+    (define-key map (kbd "r M-w") 'rec-cmd-copy-record)
+    (define-key map (kbd "s q") 'rec-cmd-select-fast)
+    (define-key map (kbd "s s") 'rec-cmd-select-sex)
+    (define-key map (kbd "h") 'rec-cmd-show-summary)
+    (define-key map (kbd "C-c t") 'rec-find-type)
     (define-key map [remap undo] 'rec-cmd-undo)
-    (define-key map "#" 'rec-cmd-count)
-    (define-key map "%" 'rec-cmd-statistic)
-    (define-key map (kbd "RET") 'rec-cmd-jump)
+    (define-key map (kbd "#") 'rec-cmd-count)
+    (define-key map (kbd "%") 'rec-cmd-statistic)
+    (define-key map [tab] 'rec-cmd-goto-next-field)
     (define-key map (kbd "TAB") 'rec-cmd-goto-next-field)
     (define-key map (kbd "SPC") 'rec-cmd-toggle-field-visibility)
-    (define-key map "b" 'rec-cmd-jump-back)
+    (define-key map (kbd "b") 'rec-cmd-jump-back)
     map)
   "Keymap for `rec-mode'.")
 
@@ -1167,9 +1168,9 @@ can then be used to toggle the visibility."
   (-head 'type)
   kind text data)
 
-(defvar rec-types                       ;FIXME: Shouldn't this be `defconst'?
+(defconst rec-types
   '("int" "bool" "range" "real" "size" "line" "regexp" "date" "enum" "field" 
"email" "uuid" "rec")
-  "Kind of supported types.")
+  "Built-in types of recutils.")
 
 (defun rec-type-kind-p (kind)
   "Determine whether the given symbol or string is a type KIND."
@@ -1186,6 +1187,8 @@ can then be used to toggle the visibility."
 
 STR must contain a type description as defined in the recutils
 manual."
+  ;; FIXME: Does not support type aliases.  Most likely this function will be
+  ;; built into recinf so that we do not do parsing in Elisp land.
   (with-temp-buffer
     (insert str)
     (goto-char (point-min))
@@ -1199,8 +1202,7 @@ manual."
               (rec-type--create (intern kind) str nil)))
            ((equal kind "size")
             (when (looking-at "[ \n\t]*\\([0-9]+\\)[ \n\t]*$")
-              ;; FIXME: A missing `'type'?  Should it call `rec-type--create'?
-              (list (intern kind) str (string-to-number (match-string 1)))))
+              (rec-type--create (intern kind) str (string-to-number 
(match-string 1)))))
            ((equal kind "range")
             (when (or
                    (looking-at "[ \n\t]*\\(-?[0-9]+\\)[ \n\t]*$")
@@ -1236,52 +1238,6 @@ manual."
            (t
             nil)))))))
 
-(defun rec-check-type (type str)
-  "Check whether STR contains a value conforming to TYPE, which is a field 
type structure."
-  (let* ((kind (rec-type-kind type))
-         ;; (expr (rec-type-text type))
-         (data (rec-type-data type))
-         (value str))
-    (cond
-     ((equal kind 'int)
-      (string-match-p "\\`-?[0-9]+\\'" value))
-     ((equal kind 'bool)
-      (string-match-p "^\\(yes\\|no\\|0\\|1\\|true\\|false\\)$" value))
-     ((equal kind 'range)
-      (let ((min (car data))
-            (max (cadr data)))
-        (when (looking-at "-?[0-9]+$") ;FIXME: `type' relates to text at point?
-          (let ((number (string-to-number (match-string 0))))
-            (and (>= number min) (<= number max))))))
-     ((equal kind 'real)
-      (string-match-p "^-?\\([0-9]*\\.\\)?[0-9]+$" value))
-     ((equal kind 'size)
-      (<= (length str) data))
-     ((equal kind 'line)
-      (string-match-p "^[^\n]*$" value))
-     ((equal kind 'regexp)
-      (string-match-p data value))
-     ((equal kind 'date)
-      ;; TODO.
-      t)
-     ((equal kind 'enum)
-      (member value data))
-     ((equal kind 'field)
-      ;; FIXME: [:alnum:]?
-      (string-match-p "\\`[a-zA-Z%][a-zA-Z0-9_]*\\'" value))
-     ((equal kind 'email)
-      ;; FIXME: [:alnum:]?
-      (string-match-p "\\`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]+\\'"
-                      value))
-     ((equal kind 'uuid)
-      ;; TODO.
-      t)
-     ((equal kind 'rec)
-      ;; TODO.
-      t)
-     (t
-      nil))))
-
 (defun rec-field-type (field-name)
   "Return the type of FIELD-NAME in determined in the current record set.
 
@@ -1593,6 +1549,10 @@ Argument SEX is the selection expression to use."
 (defvar rec-prev-buffer)                ;FIXME: Should it have a global value?
 (defvar rec-pointer)                    ;FIXME: Buffer local?  Global value?
 
+(defconst rec-cmd-edit-field-message
+  "Edit the value of the field and use \\[rec-finish-editing-field] to exit"
+  "Message to display when entering `rec-edit-field-mode'.")
+
 (defun rec-cmd-edit-field (n)
   "Edit the contents of the field under point in a separate buffer.
 
@@ -1713,7 +1673,7 @@ will be used for fields of any type."
             (insert field-value)
             (switch-to-buffer-other-window edit-buf)
             (goto-char (point-min))
-            (message "Edit the value of the field and use C-c C-c to exit"))))
+            (message (substitute-command-keys rec-cmd-edit-field-message)))))
       (message "Not in a field"))))
 
 (defun rec-finish-editing-field ()
@@ -1884,7 +1844,7 @@ Optional argument N specifies number of records to skip."
   (rec-remove-continuation-line-marker-overlays)
   (setq buffer-read-only nil)
   (use-local-map rec-mode-edit-map)
-  (rec-set-head-line "Editing record - use C-cC-c to return to navigation 
mode")
+  (rec-set-head-line (substitute-command-keys "Editing record - use 
\\[rec-finish-editing] to return to navigation mode"))
   (rec-set-mode-line "Edit record")
   (setq rec-update-p nil)
   (setq rec-preserve-last-newline t))
@@ -1902,7 +1862,7 @@ Optional argument N specifies number of records to skip."
   (setq rec-update-p t)
   (rec-set-head-line (concat "Editing type "
                              "'" (rec-record-type) "'"
-                             " - use C-cC-c to return to navigation mode"))
+                             (substitute-command-keys " - use 
\\[rec-finish-editing] to return to navigation mode")))
   (rec-set-mode-line "Edit type"))
 
 (defun rec-edit-buffer ()
@@ -1915,7 +1875,7 @@ Optional argument N specifies number of records to skip."
   (use-local-map rec-mode-edit-map)
   (widen)
   (setq rec-update-p t)
-  (rec-set-head-line "Editing buffer - use C-cC-c to return to navigation 
mode")
+  (rec-set-head-line (substitute-command-keys "Editing buffer - use 
\\[rec-finish-editing] to return to navigation mode"))
   (rec-set-mode-line "Edit buffer"))
 
 (defun rec-finish-editing ()
@@ -2235,7 +2195,7 @@ mode and show the output of recfix in a separated buffer."
 
 (defvar rec-edit-field-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "\C-c\C-c" 'rec-finish-editing-field)
+    (define-key map (kbd "C-c C-c") 'rec-finish-editing-field)
     map)
   "Keymap for `rec-edit-field-mode'.")
 
diff --git a/rec-mode.info b/rec-mode.info
index 5fbe4c7..6fd3cd6 100644
--- a/rec-mode.info
+++ b/rec-mode.info
@@ -2,7 +2,7 @@ This is rec-mode.info, produced by makeinfo version 6.7 from
 rec-mode.texi.
 
 This manual is for rec-mode for Emacs, which is part of the GNU recutils
-suite (version 1.8.90, 7 November 2020).
+suite (version 1.8.90, 13 November 2020).
 
    Copyright (C) 2012-2020 Free Software Foundation, Inc.
 
@@ -26,7 +26,7 @@ rec-mode: an Emacs mode for editing recfiles
 This manual documents version 1.8.90 of rec-mode.
 
    This manual is for rec-mode for Emacs, which is part of the GNU
-recutils suite (version 1.8.90, 7 November 2020).
+recutils suite (version 1.8.90, 13 November 2020).
 
    Copyright (C) 2012-2020 Free Software Foundation, Inc.
 
@@ -229,7 +229,7 @@ The following commands jump to other records in the buffer.
      descriptor.  then this command does nothing.
 'b'     ('rec-cmd-jump-back')
      Display the record previously displayed in the buffer.
-'C-c t'     ('rec-find-type')
+'C-c C-t'     ('rec-find-type')
      Prompt the user for one of the record types present in the recfile
      and display the first record of the selected type.
 
@@ -385,9 +385,12 @@ recfile: record, record type and buffer.  When an edition 
mode is
 entered the buffer is set in read/write mode, it is narrowed to the
 desired area and any embellishment used in navigation mode is
 removed(1).  As a general rule, the commands available in navigation
-mode are also available in the edition mode prefixed with 'C-c'.  Thus,
-'C-c n' would make the cursor to jump to the beginning of the next
-record.
+mode are also available in the edition mode prefixed with 'C-c' and with
+a control sequence 'C-'.  Thus, 'n', which in record navigation mode
+jumps to the next record, becomes 'C-c C-n' in the record edition modes.
+The exceptions to this are the bindings 'c' ('rec-cmd-compile') which
+becomes 'C-c C-k' and 'h' ('rec-cmd-show-summary') which becomes 'C-c
+M-h'.
 
    The following commands are used to enter into one of the available
 edition modes from the navigation mode.
@@ -943,28 +946,28 @@ their use in free software.
 
 
 Tag Table:
-Node: Top771
-Node: Introduction2844
-Ref: Introduction-Footnote-13595
-Node: Installation3642
-Node: Activation4759
-Ref: Activation-Footnote-15426
-Node: Feedback5552
-Ref: Feedback-Footnote-15970
-Node: Navigation mode6191
-Node: Record navigation7929
-Node: Field navigation8883
-Node: Field folding9559
-Node: Field edition10305
-Node: Searches12099
-Node: Statistics12875
-Node: Data integrity13944
-Node: Edition modes14456
-Ref: Edition modes-Footnote-116131
-Node: Configuration16162
-Node: Finding the recutils16463
-Node: Records appearance17077
-Node: GNU Free Documentation License17580
+Node: Top772
+Node: Introduction2846
+Ref: Introduction-Footnote-13597
+Node: Installation3644
+Node: Activation4761
+Ref: Activation-Footnote-15428
+Node: Feedback5554
+Ref: Feedback-Footnote-15972
+Node: Navigation mode6193
+Node: Record navigation7931
+Node: Field navigation8887
+Node: Field folding9563
+Node: Field edition10309
+Node: Searches12103
+Node: Statistics12879
+Node: Data integrity13948
+Node: Edition modes14460
+Ref: Edition modes-Footnote-116349
+Node: Configuration16380
+Node: Finding the recutils16681
+Node: Records appearance17295
+Node: GNU Free Documentation License17798
 
 End Tag Table
 
diff --git a/rec-mode.texi b/rec-mode.texi
index 9b750ed..3332862 100644
--- a/rec-mode.texi
+++ b/rec-mode.texi
@@ -2,7 +2,7 @@
 @comment %**start of header
 @setfilename rec-mode.info
 @settitle rec-mode for Emacs
-@set UPDATED 7 November 2020
+@set UPDATED 13 November 2020
 @set EDITION 1.8.90
 @set VERSION 1.8.90
 @afourpaper
@@ -245,7 +245,7 @@ the current record is anonymous, @ie{} there is not record
 descriptor. then this command does nothing.
 @reccmd{b, rec-cmd-jump-back}
 Display the record previously displayed in the buffer.
-@reccmd{C-c t, rec-find-type}
+@reccmd{C-c C-t, rec-find-type}
 Prompt the user for one of the record types present in the recfile and
 display the first record of the selected type.
 @end table
@@ -394,8 +394,12 @@ entered the buffer is set in read/write mode, it is 
narrowed to the
 desired area and any embellishment used in navigation mode is
 removed@footnote{Exceptuating font-lock}.  As a general rule, the
 commands available in navigation mode are also available in the
-edition mode prefixed with @kbd{C-c}.  Thus, @kbd{C-c n} would make
-the cursor to jump to the beginning of the next record.
+edition mode prefixed with @kbd{C-c} and with a control sequence
+@kbd{C-}.  Thus, @kbd{n}, which in record navigation mode jumps to the
+next record, becomes @kbd{C-c C-n} in the record edition modes.  The
+exceptions to this are the bindings @kbd{c}
+(@command{rec-cmd-compile}) which becomes @kbd{C-c C-k} and @kbd{h}
+(@command{rec-cmd-show-summary}) which becomes @kbd{C-c M-h}. 
 
 The following commands are used to enter into one of the available
 edition modes from the navigation mode.
-- 
2.24.3 (Apple Git-128)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]