1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-21 06:55:35 +00:00

Replace use of if-let and when-let, obsolete in Emacs 31.0.50

* lisp/ob-R.el (org-babel-R-associate-session):
* lisp/ob-clojure.el (ob-clojure-nbb-command, ob-clojure-cli-command):
* lisp/ob-core.el (org-babel-execute-src-block):
* lisp/ob-exp.el (org-babel-exp-code):
* lisp/ob-julia.el (org-babel-julia-associate-session):
* lisp/ob-python.el
(org-babel-python--python-util-comint-end-of-output-p):
* lisp/ol.el (org-insert-link):
* lisp/org-attach.el (org-attach):
* lisp/org-clock.el (org-clock-select-task):
* lisp/org-compat.el (fboundp):
* lisp/org-element-ast.el (org-element-property-raw)
(org-element-put-property, org-element-copy):
* lisp/org-element.el (org-element-timestamp-interpreter)
(org-element--cache-key):
* lisp/org-goto.el (org-goto-location):
* lisp/org-lint.el (org-lint-suspicious-language-in-src-block)
(org-lint-export-option-keywords):
* lisp/org-macs.el (org-mks):
* lisp/org-persist.el: (org-persist-write:elisp):
* lisp/org-table.el (org-table-fedit-finish, orgtbl--skip)
(orgtbl--skipcols):
* lisp/org.el (org-entry-get-with-inheritance):
* lisp/ox-beamer.el (org-beamer--format-frame):
* lisp/ox-html.el (org-html--reference, org-html--build-mathjax-config)
(org-html-example-block):
* lisp/ox-latex.el (org-latex-table-row):
* lisp/ox.el (org-export--prune-tree)
(org-export--blindly-expand-include):
* testing/lisp/test-duplicates-detector.el
(test-duplicates-detector--find-duplicates):
* testing/lisp/test-ob-haskell-ghci.el
(test-ob-haskell-ghci-checking-buffers):
* testing/lisp/test-ob-python.el
(test-ob-python/async-local-python-shell):
* testing/lisp/test-ob-shell.el (test-ob-shell/bash-uses-assoc-arrays)
(test-ob-shell/bash-uses-assoc-arrays-with-lists)
(test-ob-shell/remote-with-stdin-or-cmdline):
Replace use of if-let and when-let, obsolete in Emacs 31.0.50.
This commit is contained in:
Sean Whitton 2024-10-24 17:04:40 +08:00
parent 3aba4f191b
commit bc7033f2d1
26 changed files with 62 additions and 62 deletions

View File

@ -294,7 +294,7 @@ Retrieve variables from PARAMS."
"Associate R code buffer with an R session.
Make SESSION be the inferior ESS process associated with the
current code buffer."
(when-let ((process (get-buffer-process session)))
(when-let* ((process (get-buffer-process session)))
(setq ess-local-process-name (process-name process))
(ess-make-buffer-current))
(setq-local ess-gen-proc-buffer-name-function (lambda (_) session)))

View File

@ -120,14 +120,14 @@
:package-version '(Org . "9.6"))
(defcustom ob-clojure-nbb-command (or (executable-find "nbb")
(when-let (npx (executable-find "npx"))
(when-let* ((npx (executable-find "npx")))
(concat npx " nbb")))
"Nbb command used by the ClojureScript `nbb' backend."
:type '(choice string (const nil))
:group 'org-babel
:package-version '(Org . "9.7"))
(defcustom ob-clojure-cli-command (when-let (cmd (executable-find "clojure"))
(defcustom ob-clojure-cli-command (when-let* ((cmd (executable-find "clojure")))
(concat cmd " -M"))
"Clojure CLI command used by the Clojure `clojure-cli' backend."
:type '(choice string (const nil))

View File

@ -887,7 +887,7 @@ guess will be made."
(default-directory
(cond
((not dir) default-directory)
((when-let ((session (org-babel-session-buffer info)))
((when-let* ((session (org-babel-session-buffer info)))
(buffer-local-value 'default-directory (get-buffer session))))
((member mkdirp '("no" "nil" nil))
(file-name-as-directory (expand-file-name dir)))

View File

@ -441,7 +441,7 @@ replaced with its value."
("header-args"
.
,(org-babel-exp--at-source
(when-let ((params (org-element-property :parameters (org-element-context))))
(when-let* ((params (org-element-property :parameters (org-element-context))))
(concat " " params))))
,@(mapcar (lambda (pair)
(cons (substring (symbol-name (car pair)) 1)

View File

@ -79,7 +79,7 @@
"Associate R code buffer with an R session.
Make SESSION be the inferior ESS process associated with the
current code buffer."
(when-let ((process (get-buffer-process session)))
(when-let* ((process (get-buffer-process session)))
(setq ess-local-process-name (process-name process))
(ess-make-buffer-current))
(setq-local ess-gen-proc-buffer-name-function (lambda (_) session)))

View File

@ -269,7 +269,7 @@ results as a string."
"Return non-nil if the last prompt matches input prompt.
Backport of `python-util-comint-end-of-output-p' to emacs28. To
be removed after minimum supported version reaches emacs29."
(when-let ((prompt (python-util-comint-last-prompt)))
(when-let* ((prompt (python-util-comint-last-prompt)))
(python-shell-comint-end-of-output-p
(buffer-substring-no-properties
(car prompt) (cdr prompt)))))

View File

@ -2098,7 +2098,7 @@ non-interactively, don't allow editing the default description."
(setq link (substring link 0 -1))))
(setq link (with-current-buffer origbuf
(org-link--try-special-completion link)))))
(when-let ((window (get-buffer-window "*Org Links*" t)))
(when-let* ((window (get-buffer-window "*Org Links*" t)))
(quit-window 'kill window))
(set-window-configuration wcf)
(when (get-buffer "*Org Links*")

View File

@ -357,7 +357,7 @@ Shows a list of commands and prompts for another key to execute a command."
(while (and (setq c (read-char-exclusive))
(memq c '(?\C-n ?\C-p ?\C-v ?\M-v)))
(org-scroll c t)))
(when-let ((window (get-buffer-window "*Org Attach*" t)))
(when-let* ((window (get-buffer-window "*Org Attach*" t)))
(quit-window 'kill window))
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*")))))
(let ((command (cl-some (lambda (entry)

View File

@ -698,7 +698,7 @@ there is no recent clock to choose from."
(fit-window-to-buffer nil nil (if (< chl 10) chl (+ 5 chl)))
(message (or prompt "Select task for clocking:"))
(unwind-protect (setq cursor-type nil rpl (read-char-exclusive))
(when-let ((window (get-buffer-window "*Clock Task Select*" t)))
(when-let* ((window (get-buffer-window "*Clock Task Select*" t)))
(quit-window 'kill window))
(when (get-buffer "*Clock Task Select*")
(kill-buffer "*Clock Task Select*")))

View File

@ -115,10 +115,10 @@ This is an action function for buffer display, see Info
node `(elisp) Buffer Display Action Functions'. It should be
called only by `display-buffer' or a function directly or
indirectly called by the latter."
(when-let ((window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-pop-up-window buffer alist)
(display-buffer-use-some-window buffer alist))))
(when-let* ((window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-pop-up-window buffer alist)
(display-buffer-use-some-window buffer alist))))
(delete-other-windows window)
window)))

View File

@ -410,7 +410,7 @@ If PROPERTY is not present, return DFLT."
(let ((idx (org-element--property-idx (inline-const-val property))))
(inline-quote
(let ((idx (or ,idx (org-element--property-idx ,property))))
(if-let ((parray (and idx (org-element--parray ,node))))
(if-let* ((parray (and idx (org-element--parray ,node))))
(pcase (aref parray idx)
(`org-element-ast--nil ,dflt)
(val val))
@ -456,7 +456,7 @@ Return modified NODE."
(inline-quote
(let ((idx (org-element--property-idx ,property)))
(if (and idx (not (org-element-type-p ,node 'plain-text)))
(when-let
(when-let*
((parray
(or (org-element--parray ,node)
(org-element--put-parray ,node))))
@ -796,7 +796,7 @@ When DATUM is `plain-text', all the properties are removed."
(type
(let ((node-copy (append (list type (copy-sequence (cadr datum))) (copy-sequence (cddr datum)))))
;; Copy `:standard-properties'
(when-let ((parray (org-element-property-raw :standard-properties node-copy)))
(when-let* ((parray (org-element-property-raw :standard-properties node-copy)))
(org-element-put-property node-copy :standard-properties (copy-sequence parray)))
;; Clear `:parent'.
(org-element-put-property node-copy :parent nil)
@ -810,7 +810,7 @@ When DATUM is `plain-text', all the properties are removed."
;; properties. So, we need to reassign inner `:parent'
;; properties to the DATUM copy explicitly.
(dolist (secondary-prop (org-element-property :secondary node-copy))
(when-let ((secondary-value (org-element-property secondary-prop node-copy)))
(when-let* ((secondary-value (org-element-property secondary-prop node-copy)))
(setq secondary-value (org-element-copy secondary-value t))
(if (org-element-type secondary-value)
(org-element-put-property secondary-value :parent node-copy)

View File

@ -4453,10 +4453,10 @@ Assume point is at the beginning of the timestamp."
(and val (number-to-string val)))
(pcase (org-element-property :repeater-unit timestamp)
(`hour "h") (`day "d") (`week "w") (`month "m") (`year "y"))
(when-let ((repeater-deadline-value
(org-element-property :repeater-deadline-value timestamp))
(repeater-deadline-unit
(org-element-property :repeater-deadline-unit timestamp)))
(when-let* ((repeater-deadline-value
(org-element-property :repeater-deadline-value timestamp))
(repeater-deadline-unit
(org-element-property :repeater-deadline-unit timestamp)))
(concat
"/"
(number-to-string repeater-deadline-value)
@ -6010,7 +6010,7 @@ cache during the synchronization get a new key generated with
Such keys are stored inside the element property
`:org-element--cache-sync-key'. The property is a cons containing
current `org-element--cache-sync-keys-value' and the element key."
(or (when-let ((key-cons (org-element-property :org-element--cache-sync-key element)))
(or (when-let* ((key-cons (org-element-property :org-element--cache-sync-key element)))
(when (eq org-element--cache-sync-keys-value (car key-cons))
(cdr key-cons)))
(let* ((begin (org-element-begin element))

View File

@ -241,7 +241,7 @@ position or nil."
(message "Select location and press RET")
(use-local-map org-goto-map)
(unwind-protect (recursive-edit)
(when-let ((window (get-buffer-window "*Org Help*" t)))
(when-let* ((window (get-buffer-window "*Org Help*" t)))
(quit-window 'kill window)))))
(when (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
(cons org-goto-selected-point org-goto-exit-command)))

View File

@ -561,7 +561,7 @@ Use :header-args: instead"
(defun org-lint-suspicious-language-in-src-block (ast)
(org-element-map ast 'src-block
(lambda (b)
(when-let ((lang (org-element-property :language b)))
(when-let* ((lang (org-element-property :language b)))
(unless (or (functionp (intern (format "org-babel-execute:%s" lang)))
;; No babel backend, but there is corresponding
;; major mode.
@ -869,9 +869,9 @@ Use \"export %s\" instead"
(when (member prop common-options)
"global ")
prop
(if-let ((backends
(and (not (member prop common-options))
(cdr (assoc-string prop options-alist)))))
(if-let* ((backends
(and (not (member prop common-options))
(cdr (assoc-string prop options-alist)))))
(format
" in %S export %s"
(if (= 1 (length backends)) (car backends) backends)

View File

@ -573,7 +573,7 @@ is selected, only the bare key is returned."
((assoc current specials) (throw 'exit current))
(t (error "No entry available")))))))
(when buffer
(when-let ((window (get-buffer-window buffer t)))
(when-let* ((window (get-buffer-window buffer t)))
(quit-window 'kill window))
(kill-buffer buffer))))))

View File

@ -829,8 +829,8 @@ COLLECTION is the plist holding data collection."
(let ((scope (nth 2 container)))
(pcase scope
((pred stringp)
(when-let ((buf (or (get-buffer scope)
(get-file-buffer scope))))
(when-let* ((buf (or (get-buffer scope)
(get-file-buffer scope))))
;; FIXME: There is `buffer-local-boundp' introduced in Emacs 28.
;; Not using it yet to keep backward compatibility.
(condition-case nil
@ -846,8 +846,8 @@ COLLECTION is the plist holding data collection."
;; necessarily be the case in general and we may initiate
;; writing cache in one buffer, but `get-file-buffer' may then
;; return _another_ buffer (with the same `buffer-file-name').
(if-let ((buf (and (plist-get (plist-get collection :associated) :file)
(get-file-buffer (plist-get (plist-get collection :associated) :file)))))
(if-let* ((buf (and (plist-get (plist-get collection :associated) :file)
(get-file-buffer (plist-get (plist-get collection :associated) :file)))))
;; FIXME: There is `buffer-local-boundp' introduced in Emacs 28.
;; Not using it yet to keep backward compatibility.
(condition-case nil

View File

@ -3709,7 +3709,7 @@ With prefix ARG, apply the new formulas to the table."
(org-table-store-formulas eql)
(set-marker pos nil)
(set-marker source nil)
(when-let ((window (get-buffer-window "*Edit Formulas*" t)))
(when-let* ((window (get-buffer-window "*Edit Formulas*" t)))
(quit-window 'kill window))
(when (get-buffer "*Edit Formulas*") (kill-buffer "*Edit Formulas*"))
(if arg
@ -5658,7 +5658,7 @@ First element has index 0, or I0 if given."
"Extract first X table rows from AST.
X is taken from :skip property in INFO plist.
Return the modified AST."
(when-let ((skip (plist-get info :skip)))
(when-let* ((skip (plist-get info :skip)))
(unless (wholenump skip) (user-error "Wrong :skip value"))
(let ((n 0))
(org-element-map ast 'table-row
@ -5675,7 +5675,7 @@ Return the modified AST."
X is taken from :skipcols property in INFO plist.
Special columns are always ignored.
Return the modified AST."
(when-let ((skipcols (plist-get info :skipcols)))
(when-let* ((skipcols (plist-get info :skipcols)))
(unless (consp skipcols) (user-error "Wrong :skipcols value"))
(org-element-map ast 'table
(lambda (table)

View File

@ -13236,8 +13236,8 @@ However, if LITERAL-NIL is set, return the string value \"nil\" instead."
;; Consider global properties, if we found no PROPERTY (or maybe
;; only PROPERTY+).
(unless found-inherited?
(when-let ((global (org--property-global-or-keyword-value
property t)))
(when-let* ((global (org--property-global-or-keyword-value
property t)))
(setq values (cons global values))))
(when values
(setq values (mapconcat

View File

@ -501,8 +501,8 @@ used as a communication channel."
(org-export-data
(org-element-property :title headline) info))))
;; Subtitle
(when-let ((subtitle
(org-element-property :BEAMER_SUBTITLE headline)))
(when-let* ((subtitle
(org-element-property :BEAMER_SUBTITLE headline)))
(format "{%s}"
(org-export-data
(org-element-parse-secondary-string

View File

@ -1735,7 +1735,7 @@ targets and targets."
(and (memq type '(radio-target target))
(org-element-property :value datum))
(org-element-property :name datum)
(when-let ((id (org-element-property :ID datum)))
(when-let* ((id (org-element-property :ID datum)))
(concat org-html--id-attr-prefix id)))))
(cond
@ -2065,7 +2065,7 @@ INFO is a plist used as a communication channel."
(when value
(pcase symbol
(`font
(when-let
(when-let*
((value-new
(pcase value
("TeX" "mathjax-tex")
@ -2710,7 +2710,7 @@ information."
(let ((attributes (org-export-read-attribute :attr_html example-block)))
(if (plist-get attributes :textarea)
(org-html--textarea-block example-block)
(if-let ((class-val (plist-get attributes :class)))
(if-let* ((class-val (plist-get attributes :class)))
(setq attributes (plist-put attributes :class (concat "example " class-val)))
(setq attributes (plist-put attributes :class "example")))
(format "<pre%s>\n%s</pre>"

View File

@ -4097,7 +4097,7 @@ a communication channel."
(unless (hash-table-p table-head-cache)
(setq table-head-cache (make-hash-table :test #'eq))
(plist-put info :org-latex-table-head-cache table-head-cache))
(if-let ((head-contents (gethash (org-element-parent table-row) table-head-cache)))
(if-let* ((head-contents (gethash (org-element-parent table-row) table-head-cache)))
(puthash (org-element-parent table-row) (concat head-contents "\\\\\n" contents)
table-head-cache)
(puthash (org-element-parent table-row) contents table-head-cache))))

View File

@ -2680,7 +2680,7 @@ from tree."
(let ((type (org-element-type data)))
(if (org-export--skip-p data info selected excluded)
(if (memq type '(table-cell table-row)) (push data ignore)
(if-let ((keep-spaces (org-export--keep-spaces data info)))
(if-let* ((keep-spaces (org-export--keep-spaces data info)))
;; Keep spaces in place of removed
;; element, if necessary.
;; Example: "Foo.[10%] Bar" would become
@ -3465,7 +3465,7 @@ file."
(with-temp-buffer
(let ((org-inhibit-startup t)
(lines
(if-let ((location (plist-get parameters :location)))
(if-let* ((location (plist-get parameters :location)))
(org-export--inclusion-absolute-lines
file location
(plist-get parameters :only-contents)

View File

@ -150,17 +150,17 @@ Duplicate forms will be written to
(while (setq deftest (read (current-buffer)))
(setq test-name (cadr deftest))
(when (eq (car deftest) 'ert-deftest)
(if-let ((f (seq-find
(lambda (x)
(equal-including-properties
;; if cadddr is a docstring
(if (stringp (cadddr deftest))
(cddddr deftest)
(cdddr deftest))
(if (stringp (cadddr x))
(cddddr x)
(cdddr x))))
found-deftests)))
(if-let* ((f (seq-find
(lambda (x)
(equal-including-properties
;; if cadddr is a docstring
(if (stringp (cadddr deftest))
(cddddr deftest)
(cdddr deftest))
(if (stringp (cadddr x))
(cddddr x)
(cdddr x))))
found-deftests)))
(push (cons test-name (cadr f)) duplicate-tests)
(push deftest found-deftests)
(test-duplicates-detector--search-forms-recursively

View File

@ -45,7 +45,7 @@
(when (get-buffer "*haskell*")
(error "A buffer named '*haskell*' exists. Can't safely test haskell blocks"))
(prog1 (funcall todo)
(when-let ((hb (get-buffer "*haskell*")))
(when-let* ((hb (get-buffer "*haskell*")))
;; We created a "*haskell*" buffer. That shouldn't happen.
(error "'ob-haskell' created a buffer named '*haskell*'"))))

View File

@ -300,7 +300,7 @@ print(list(range(3)))
;; Disable the test on older Emacs as built-in python.el sometimes
;; fail to initialize session.
(skip-unless (version<= "28" emacs-version))
(when-let ((buf (get-buffer "*Python*")))
(when-let* ((buf (get-buffer "*Python*")))
(let (kill-buffer-query-functions)
(kill-buffer buf)))
(org-test-with-temp-text-in-file

View File

@ -232,7 +232,7 @@ Bash will see a table that contains the first column as the
value. "
(skip-unless
;; Old GPLv2 BASH in macOSX does not support associative arrays.
(if-let ((bash (executable-find "bash")))
(if-let* ((bash (executable-find "bash")))
(eq 0 (process-file bash nil nil nil "-c" "declare -A assoc_array"))))
(org-test-with-temp-text
"#+NAME: sample_mapping_table
@ -255,7 +255,7 @@ Bash will see an associative array that contains each row as a single
string. Bash cannot handle lists in associative arrays."
(skip-unless
;; Old GPLv2 BASH in macOSX does not support associative arrays.
(if-let ((bash (executable-find "bash")))
(if-let* ((bash (executable-find "bash")))
(eq 0 (process-file bash nil nil nil "-c" "declare -A assoc_array"))))
(org-test-with-temp-text
"#+NAME: sample_big_table
@ -356,7 +356,7 @@ echo ${table[spaghetti]}
(params-line "")
(who-line " export who=tramp")
(args-line " echo ARGS: --verbose 23 71"))
(when-let ((dir (plist-get spec :dir)))
(when-let* ((dir (plist-get spec :dir)))
(setq params-line (concat params-line " " ":dir " dir)))
(when (plist-get spec :stdin)
(setq who-line " read -r who")