summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-17 00:31:39 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-17 00:31:39 +0100
commit8f540c4db446a664089fb09b5b4a8e6c8510e114 (patch)
tree4977c52dba85c52c2e5fd86e976b5182691a072c
parent1d8d83d8757794f11ccf890ee8224796f660cfc8 (diff)
downloadorg-mode-8f540c4db446a664089fb09b5b4a8e6c8510e114.tar.gz
org-list: Optimize `org-at-radio-list-p'
* lisp/org-list.el (org-at-radio-list-p): Call only one "heavy" function. Do not require "ox.el" function. Use defun instead of defsubst since this is a non-trivial function. For consistency with other parameters, :radio accepts any value except nil.
-rw-r--r--lisp/org-list.el25
1 files changed, 14 insertions, 11 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 726bc72..46cae54 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -2337,17 +2337,20 @@ is an integer, 0 means `-', 1 means `+' etc. If WHICH is
(org-list-struct-apply-struct struct old-struct)
(org-update-checkbox-count-maybe))))
-(defsubst org-at-radio-list-p ()
- "Is point in a list with radio buttons?"
- (when (org-at-item-p)
- (save-excursion
- (goto-char (caar (org-list-struct)))
- (ignore-errors
- (org-backward-element)
- (string= (plist-get (org-export-read-attribute
- :attr_org (org-element-at-point))
- :radio)
- "t")))))
+(defun org-at-radio-list-p ()
+ "Is point at a list item with radio buttons?"
+ (when (org-match-line (org-item-re)) ;short-circuit
+ (let* ((e (save-excursion (beginning-of-line) (org-element-at-point))))
+ ;; Check we're really on a line with a bullet.
+ (when (memq (org-element-type e) '(item plain-list))
+ ;; Look for ATTR_ORG attribute in the current plain list.
+ (let ((plain-list (org-element-lineage e '(plain-list) t)))
+ (org-with-point-at (org-element-property :post-affiliated plain-list)
+ (let ((case-fold-search t)
+ (regexp "^[ \t]*#\\+attr_org:.* :radio \\(\\S-+\\)")
+ (begin (org-element-property :begin plain-list)))
+ (and (re-search-backward regexp begin t)
+ (not (string-equal "nil" (match-string 1)))))))))))
(defun org-toggle-checkbox (&optional toggle-presence)
"Toggle the checkbox in the current line.