Remove the broken `get-org-table-fix-info' to start replacing it

This commit is contained in:
Gerard Vermeulen 2023-07-05 04:21:53 +02:00
parent 8e5f521332
commit bfb3d4a073
1 changed files with 106 additions and 80 deletions

View File

@ -2810,17 +2810,6 @@ SCHEDULED: <2023-06-30 Fri>
| | | Classic | | |
| Goldberg Variations | G. Gould | Classic Baroque | 1 | Deutsche Grammophon |
,#+END:
,#+BEGIN_SRC emacs-lisp :results pp :wrap "src emacs-lisp :eval never"
(get-org-table-fix-info 10 1)
,#+END_SRC
,#+RESULTS:
,#+begin_src emacs-lisp :eval never
((dynamic-block "CD collection" 902 1377
(:hlines 1 :id "CD collection")
"columnview"))
,#+end_src
#+end_src
*** Org introspection
@ -3037,79 +3026,116 @@ The property is from the drawer of headline matching TARGET and LEVEL."
(unless match (message "Can't find \"#+COLUMNS:\" keyword")))))
#+end_src
#+caption[Help to make tables from org-insert-columns-dblock blocks]:
#+caption: Help to make tables from org-insert-columns-dblock blocks.
#+name: lst:get-org-table-fix-info
#+begin_src emacs-lisp :results silent
(defun get-org-table-fix-info (limit debug)
(let ((done nil) (n 0))
(org-with-point-at 1
(while (and (< n limit)
(re-search-forward org-table-line-regexp nil t))
(setq n (1+ n))
(let* ((eap (org-element-at-point))
(k (car eap))
(p (plist-get (cadr eap) :parent))
(kk (car p))
(pp (plist-get (cadr p) :parent))
(kkk (car pp)))
(when (> debug 0)
(message "k=`%s' kk=`%s' kkk=`%s'" k kk kkk))
(when-let ((ok (and (eq k 'table-row)
(eq kk 'table)
(eq kkk 'dynamic-block)))
(beg (plist-get (cadr pp) :begin))
(end (plist-get (cadr pp) :end)))
(push (list 'dynamic-block (plist-get (cadr pp) :name) beg end
(read (concat "(" (plist-get (cadr pp) :arguments) ")"))
(plist-get (cadr pp) :block-name))
done)
(goto-char end))
(when-let ((ok (and (eq k 'table-row)
(eq kk 'table)
(eq kkk 'section)))
(beg (plist-get (cadr p) :begin))
(end (plist-get (cadr p) :end)))
(when (> debug 0)
(push (list 'table (plist-get (cadr p) :name) beg end) done))
(goto-char end))
(when-let ((ok (eq k 'src-block))
(end (plist-get (cadr eap) :end))
(beg (plist-get (cadr eap) :begin)))
(when (> debug 0)
(push (list 'src-block (plist-get (cadr eap) :name) beg end) done))
(goto-char end))
(when (> debug 1)
(pp-display-expression eap grok-org-output)))))
(nreverse done)))
#+name: lst:tables-and-headings
#+begin_src emacs-lisp -n :lexical t :results silent
(with-eval-after-load 'org
(defun all-org-heading-components (max-level)
"Find all MAX-LEVEL `org-heading-components' prefixed by `pos-bol'."
(let ((done nil))
(org-with-point-at 1
(let ((regexp (org-headline-re max-level)))
;; The `noerror' argument must be `t' instead of `noerror':
(while (re-search-forward regexp nil t)
(push (cons (pos-bol) (org-heading-components)) done))))
(sort done (lambda (x y) (< (car x) (car y))))))
(defun all-org-table-indices ()
(let ((done nil))
(org-with-point-at 1
(while (re-search-forward org-table-line-regexp nil t)
(let ((table (org-element-lineage (org-element-at-point) 'table t)))
(when table
;; `org' tables have contents (`table.el' tables have value)
(cl-pushnew (list (org-element-begin table)
(org-element-contents-begin table)
(org-element-contents-end table))
done :test 'equal)))))
(cl-loop for (x y z) in (sort done (lambda (x y) (< (car x) (car y))))
collect (list x y z))))
(defun all-org-table-contents ()
(let ((done nil))
(org-with-point-at 1
(while (re-search-forward org-table-line-regexp nil t)
(let ((table (org-element-lineage (org-element-at-point) 'table t)))
(when table
;; `org' tables have contents (`table.el' tables have value)
(cl-pushnew (list (org-element-begin table)
(org-element-contents-begin table)
(org-element-contents-end table))
done :test 'equal)))))
(cl-loop for (x y z) in (sort done (lambda (x y) (< (car x) (car y))))
collect (list x y z (buffer-substring-no-properties y z))))))
#+end_src
#+caption[Test ~get-org-table-fix-info~]:
#+caption: Test ~get-org-table-fix-info~ with ~limit=10~ and ~debug=1~.
#+header: :wrap "src emacs-lisp :eval never :results silent :tangle no"
#+header: :var limit=10 debug=1
#+name: lst:test-get-org-table-fix-info
#+begin_src emacs-lisp :exports both :results value pp :tangle no
(get-org-table-fix-info limit debug)
#+caption[Test ~all-org-heading-components~]:
#+caption: Test ~all-org-heading-components~ with ~depth=1~.
#+header: :var depth=1
#+header: :wrap "src emacs-lisp -n :eval never :tangle no"
#+name: test-all-org-heading-components
#+begin_src emacs-lisp -n :exports both :lexical t :results value pp :tangle no
(all-org-heading-components depth)
#+end_src
#+caption[Test ~get-org-table-fix-info~ results]:
#+caption: Test ~get-org-table-fix-info~ results.
#+caption: The code identifies the captured column view in listing
#+caption: [[lst:property-syntax-demonstration][property syntax demonstration]] as a table in a source block
#+caption: instead of a captured column view in a source block.
#+name: lst:test-get-org-table-fix-info-results
#+RESULTS: lst:test-get-org-table-fix-info
#+begin_src emacs-lisp :eval never :results silent :tangle no
((table "tab:help-key-bindings" 44294 45056)
(table "tab:basic-key-bindings" 48716 49583)
(table "tab:vertico-keymap-bindings" 61941 64095)
(table "tab:configuration-specific-key-bindings" 67472 70699)
(table "tab:replace-regexp-tranform" 74245 74969)
(table "tab:org-latex-class-tag-placeholder" 112066 112576)
(src-block "lst:property-syntax-demonstration" 121141 123013)
(table "tab:eglot-related-key-bindings" 269511 270310)
(table "tab:gnus-key-bindings" 309804 310380))
#+caption[Test ~all-org-heading-components~ result]:
#+caption: Test ~all-org-heading-components~ result with ~depth=1~.
#+name: test-all-org-heading-components-result
#+RESULTS: test-all-org-heading-components
#+begin_src emacs-lisp -n :eval never :tangle no
((569 1 1 nil nil "Copying" nil)
(1874 1 1 nil nil "Quick start" nil)
(3580 1 1 nil nil "Introduction" nil)
(10948 1 1 nil nil "[[info:emacs#Early Init File][Early Init File (info)]]" nil)
(12233 1 1 nil nil "[[info:emacs#Init File][Init File (info)]] header" nil)
(19176 1 1 nil nil "[[info:emacs#Package Installation][Install the selected packages (info)]]" nil)
(22176 1 1 nil nil "[[https://git.savannah.gnu.org/cgit/emacs.git/tree/admin/notes/tree-sitter/starter-guide?h=feature/tree-sitter][Emacs Tree-sitter]]" nil)
(25198 1 1 nil nil "[[info:emacs#Faces][Text faces or styles (info)]]" nil)
(32177 1 1 nil nil "[[info:emacs#Windows][Window management (info)]]" nil)
(35290 1 1 nil nil "[[info:elisp#Advising Functions][Advising functions (info)]]" nil)
(37117 1 1 nil nil "[[info:emacs#Dired][Dired: directory editor as file manager (info)]]" nil)
(42683 1 1 nil nil "[[info:emacs#Completion Styles][Minibuffer completion styles (info)]]" nil)
(43488 1 1 nil nil "[[info:elisp#Processes][Processes (info)]]" nil)
(44281 1 1 nil nil "[[info:emacs#Help][Help (info)]]" nil)
(48866 1 1 nil nil "[[info:emacs#Key Bindings][Key bindings (info)]]" nil)
(53746 1 1 nil nil "[[info:emacs#Emacs Server][Using Emacs as a server (info)]]" nil)
(59498 1 1 nil nil "Completion" nil)
(73230 1 1 nil nil "[[info:emacs#Search][Search and replace (info)]]" nil)
(79650 1 1 nil nil "[[info:emacs#Version Control][Version Control (info)]]" nil)
(84604 1 1 nil nil "Reading" nil)
(87677 1 1 nil nil "Writing" nil)
(189130 1 1 nil nil "Programming Tools" nil)
(198923 1 1 nil nil "Programming Modes" nil)
(279054 1 1 nil nil "[[https://github.com/emacs-tw/awesome-emacs#library][Libraries]]" nil)
(281025 1 1 nil nil "[[info:emacs#Minor Modes][Minor Modes (info)]]" nil)
(294147 1 1 nil nil "[[info:emacs#Display][Display (info)]]" nil)
(298934 1 1 nil nil "Applications" nil)
(322732 1 1 nil nil "[[info:emacs#Init File][Init File (info)]] footer" nil)
(323197 1 1 nil nil "GNU General Public License" nil)
(323361 1 1 nil nil "GNU Free Documentation License" nil)
(323458 1 1 nil nil "Local variables linking to [[#sec:latexmk-save-compile-display-loop][Latexmk save-compile-display-loop]]" nil))
#+end_src
#+caption[Test ~all-org-table-indices~]:
#+caption: Test ~all-org-table-indices~.
#+name: test-all-org-table-indices
#+header: :wrap "src emacs-lisp -n :eval never :tangle no"
#+begin_src emacs-lisp -n :exports both :lexical t :results value pp :tangle no
(all-org-table-indices)
#+end_src
#+caption[Test ~all-org-table-indices~ result]:
#+caption: Test ~all-org-table-indices~ result.
#+name: test-all-org-table-indices-result
#+RESULTS: test-all-org-table-indices
#+begin_src emacs-lisp -n :eval never :tangle no
((44544 44675 45305)
(48966 49100 49832)
(62191 62342 64344)
(67722 67907 70947)
(74495 74726 75218)
(112316 112569 112825)
(271582 271740 272380)
(311875 312006 312450))
#+end_src
*** [[https://github.com/bdarcus/citar][Citar: citing bibliography]] with [[https://orgmode.org/][Org Mode]]