emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Free up C-c SPC/org-table-blank-field?


From: Kyle Meyer
Subject: Re: Free up C-c SPC/org-table-blank-field?
Date: Thu, 04 Feb 2021 23:45:14 -0500

Eric Abrahamsen writes:

> Kyle Meyer <kyle@kyleam.com> writes:
>
[...]
>> Does it actually need a key binding? I've never used it and just use
>> <tab> to move to the next field, leaving the field blank.
>
> I assume it's meant for blanking a field you've already typed something
> into. But yes, I can't imagine it's a heavily-used command, and I
> suspect the C-c <SPC> binding is mostly mnemonic: "make this field
> contain only blanks".

[ Just for clarity: from this point on, the outer text you were quoting
  was from Tim Cross, not me. ]

> I thought Emacs might have some easy way to let a key event "fall
> through" to other keymaps, but I haven't been able to find anything
> immediately obvious. Maybe I can ask on emacs.devel...

Yeah, I don't know either.  When I read your initial message, I assumed
you were thinking of some sort of key lookup.  Something like below
seems to works, but it feels hacky and is probably pretty brittle.


diff --git a/lisp/org-table.el b/lisp/org-table.el
index ef4672e1b..c6d0e91c4 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -1203,22 +1203,28 @@ (defun org-table-goto-line (N)
     (= cnt N)))
 
 ;;;###autoload
-(defun org-table-blank-field ()
+(defun org-table-blank-field (&optional interactive-p)
   "Blank the current table field or active region."
-  (interactive)
-  (org-table-check-inside-data-field)
-  (if (and (called-interactively-p 'any) (org-region-active-p))
-      (let (org-table-clip)
-       (org-table-cut-region (region-beginning) (region-end)))
-    (skip-chars-backward "^|")
-    (backward-char 1)
-    (if (looking-at "|[^|\n]+")
-       (let* ((pos (match-beginning 0))
-              (match (match-string 0))
-              (len (org-string-width match)))
-         (replace-match (concat "|" (make-string (1- len) ?\ )))
-         (goto-char (+ 2 pos))
-         (substring match 1)))))
+  (interactive "p")
+  (cond
+   ((org-at-table-p)
+    (org-table-check-inside-data-field)
+    (if (and interactive-p (org-region-active-p))
+        (let (org-table-clip)
+          (org-table-cut-region (region-beginning) (region-end)))
+      (skip-chars-backward "^|")
+      (backward-char 1)
+      (if (looking-at "|[^|\n]+")
+          (let* ((pos (match-beginning 0))
+                 (match (match-string 0))
+                 (len (org-string-width match)))
+            (replace-match (concat "|" (make-string (1- len) ?\ )))
+            (goto-char (+ 2 pos))
+            (substring match 1)))))
+   (interactive-p
+    (let ((key (lookup-key (current-global-map) (this-command-keys))))
+      (unless (numberp key)
+        (call-interactively key))))))
 
 (defun org-table-get-field (&optional n replace)
   "Return the value of the field in column N of current row.



reply via email to

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