replace flet/labels with org-flet/org-labels

This patch ensure Org-mode will build on all supported versions of
Emacs, after the renaming of the cl macros behind the cl- prefix in the
recent Emacs trunk.

* lisp/org-compat.el (org-flet): Compatibility function now that flet
  has been removed from cl-macs.
  (org-labels): Compatibility function now that labels has been removed
  from cl-macs.
* lisp/ob-R.el (org-compat): Require org-compat.
* lisp/ob-comint.el: Require org-compat.
* lisp/ob-exp.el (org-babel-exp-do-export): Switch to compatibility
  function.
* lisp/ob-gnuplot.el (org-babel-expand-body:gnuplot): Switch to
  compatibility function.
* lisp/ob-lob.el (org-babel-lob-get-info): Switch to compatibility
  function.
  (org-babel-lob-execute): Switch to compatibility function.
* lisp/ob-python.el (org-babel-python-evaluate-session): Switch to
  compatibility function.
* lisp/ob-ref.el (org-babel-ref-index-list): Switch to compatibility
  function.
* lisp/ob-sh.el (org-babel-sh-var-to-string): Switch to compatibility
  function.
* lisp/ob-tangle.el (org-babel-load-file): Switch to compatibility
  function.
  (org-babel-tangle): Switch to compatibility function.
  (org-babel-spec-to-string): Switch to compatibility function.
* lisp/ob.el (org-babel-view-src-block-info): Switch to compatibility
  function.
  (org-babel-execute-src-block): Switch to compatibility function.
  (org-babel-edit-distance): Switch to compatibility function.
  (org-babel-switch-to-session-with-code): Switch to compatibility
  function.
  (org-babel-sha1-hash): Switch to compatibility function.
  (org-babel-balanced-split): Switch to compatibility function.
  (org-babel-join-splits-near-ch): Switch to compatibility function.
  (org-babel-get-rownames): Switch to compatibility function.
  (org-babel-format-result): Switch to compatibility function.
  (org-babel-insert-result): Switch to compatibility function.
  (org-babel-examplize-region): Switch to compatibility function.
  (org-babel-merge-params): Switch to compatibility function.
  (org-babel-noweb-p): Switch to compatibility function.
  (org-babel-expand-noweb-references): Switch to compatibility function.
* lisp/org-bibtex.el (org-bibtex-headline): Switch to compatibility
  function.
  (org-bibtex-fleshout): Switch to compatibility function.
  (org-bibtex-read): Switch to compatibility function.
  (org-bibtex-write): Switch to compatibility function.
* lisp/org-exp-blocks.el (org-export-blocks-preprocess): Switch to
  compatibility function.
* lisp/org-exp.el (org-export-format-source-code-or-example): Switch to
  compatibility function.
* lisp/org-macs.el (org-called-interactively-p): Indentation fix.
* lisp/org-mouse.el (org-mouse-timestamp-today): Switch to compatibility
  function.
  (org-mouse-set-priority): Switch to compatibility function.
  (org-mouse-popup-global-menu): Switch to compatibility function.
  (org-mouse-context-menu): Switch to compatibility function.
* lisp/org-plot.el (org-plot/gnuplot-to-grid-data): Switch to
  compatibility function.
  (org-plot/gnuplot-script): Switch to compatibility function.
* lisp/org.el (org-entry-get): Switch to compatibility function.
  (org-fill-paragraph): Switch to compatibility function.
  (org-auto-fill-function): Switch to compatibility function.
This commit is contained in:
Eric Schulte 2012-07-18 22:11:36 -06:00
parent b6b40424d2
commit 63b5f8f2e8
18 changed files with 60 additions and 47 deletions

View File

@ -33,6 +33,7 @@
;;; Code:
(require 'ob)
(require 'ob-eval)
(require 'org-compat)
(eval-when-compile (require 'cl))
(declare-function org-babel-ref-resolve "ob-ref" (ref))
@ -96,7 +97,7 @@ called by `org-babel-execute-src-block'"
(defun org-babel-awk-var-to-awk (var &optional sep)
"Return a printed value of VAR suitable for parsing with awk."
(flet ((echo-var (v) (if (stringp v) v (format "%S" v))))
(org-flet ((echo-var (v) (if (stringp v) v (format "%S" v))))
(cond
((and (listp var) (listp (car var)))
(orgtbl-to-generic var (list :sep (or sep "\t") :fmt #'echo-var)))

View File

@ -31,6 +31,7 @@
;;; Code:
(require 'ob)
(require 'org-compat)
(require 'comint)
(eval-when-compile (require 'cl))
(declare-function with-parsed-tramp-file-name "tramp" (filename var &rest body))
@ -74,7 +75,7 @@ or user `keyboard-quit' during execution of body."
(full-body (cadr (cdr (cdr meta)))))
`(org-babel-comint-in-buffer ,buffer
(let ((string-buffer "") dangling-text raw)
(flet ((my-filt (text)
(org-flet ((my-filt (text)
(setq string-buffer (concat string-buffer text))))
;; setup filter
(add-hook 'comint-output-filter-functions 'my-filt)

View File

@ -219,7 +219,7 @@ org-mode text."
(defun org-babel-exp-do-export (info type &optional hash)
"Return a string with the exported content of a code block.
The function respects the value of the :exports header argument."
(flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
(org-flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
(when (not (and session (equal "none" session)))
(org-babel-exp-results info type 'silent))))
(clean () (unless (eq type 'inline) (org-babel-remove-result info))))

View File

@ -88,7 +88,7 @@ code."
(time-ind (or (plist-get params :timeind)
(when timefmt 1)))
output)
(flet ((add-to-body (text)
(org-flet ((add-to-body (text)
(setq body (concat text "\n" body))))
;; append header argument settings to body
(when title (add-to-body (format "set title '%s'" title))) ;; title

View File

@ -97,7 +97,7 @@ if so then run the appropriate source block from the Library."
;;;###autoload
(defun org-babel-lob-get-info ()
"Return a Library of Babel function call as a string."
(flet ((nonempty (a b)
(org-flet ((nonempty (a b)
(let ((it (match-string a)))
(if (= (length it) 0) (match-string b) it))))
(let ((case-fold-search t))
@ -119,7 +119,7 @@ if so then run the appropriate source block from the Library."
(defun org-babel-lob-execute (info)
"Execute the lob call specified by INFO."
(flet ((mkinfo (p) (list "emacs-lisp" "results" p nil nil (nth 2 info))))
(org-flet ((mkinfo (p) (list "emacs-lisp" "results" p nil nil (nth 2 info))))
(let* ((pre-params (org-babel-merge-params
org-babel-default-header-args
(org-babel-params-from-properties)

View File

@ -238,7 +238,7 @@ last statement in BODY, as elisp."
If RESULT-TYPE equals 'output then return standard output as a
string. If RESULT-TYPE equals 'value then return the value of the
last statement in BODY, as elisp."
(flet ((send-wait () (comint-send-input nil t) (sleep-for 0 5))
(org-flet ((send-wait () (comint-send-input nil t) (sleep-for 0 5))
(dump-last-value
(tmp-file pp)
(mapc

View File

@ -222,7 +222,7 @@ to \"0:-1\"."
(length (length lis))
(portion (match-string 1 index))
(remainder (substring index (match-end 0))))
(flet ((wrap (num) (if (< num 0) (+ length num) num))
(org-flet ((wrap (num) (if (< num 0) (+ length num) num))
(open (ls) (if (and (listp ls) (= (length ls) 1)) (car ls) ls)))
(open
(mapcar

View File

@ -107,7 +107,7 @@ var of the same value."
(defun org-babel-sh-var-to-string (var &optional sep)
"Convert an elisp value to a string."
(flet ((echo-var (v) (if (stringp v) v (format "%S" v))))
(org-flet ((echo-var (v) (if (stringp v) v (format "%S" v))))
(cond
((and (listp var) (listp (car var)))
(orgtbl-to-generic var (list :sep (or sep "\t") :fmt #'echo-var)))

View File

@ -142,7 +142,7 @@ This function exports the source code using
`org-babel-tangle' and then loads the resulting file using
`load-file'."
(interactive "fFile to load: ")
(flet ((age (file)
(org-flet ((age (file)
(float-time
(time-subtract (current-time)
(nth 5 (or (file-attributes (file-truename file))
@ -221,7 +221,7 @@ exported source code blocks by language."
she-banged)
(mapc
(lambda (spec)
(flet ((get-spec (name)
(org-flet ((get-spec (name)
(cdr (assoc name (nth 4 spec)))))
(let* ((tangle (get-spec :tangle))
(she-bang ((lambda (sheb) (when (> (length sheb) 0) sheb))
@ -412,7 +412,7 @@ form
(if (stringp le) le (format "%S" le)))
(eval el))))
'(start-line file link source-name))))
(flet ((insert-comment (text)
(org-flet ((insert-comment (text)
(when (and comments (not (string= comments "no"))
(> (length text) 0))
(when padline (insert "\n"))

View File

@ -340,7 +340,7 @@ This includes header arguments, language and name, and is largely
a window into the `org-babel-get-src-block-info' function."
(interactive)
(let ((info (org-babel-get-src-block-info 'light)))
(flet ((full (it) (> (length it) 0))
(org-flet ((full (it) (> (length it) 0))
(printf (fmt &rest args) (princ (apply #'format fmt args))))
(when info
(with-help-window (help-buffer)
@ -536,9 +536,9 @@ block."
(indent (car (last info)))
result cmd)
(unwind-protect
(flet ((call-process-region (&rest args)
(org-flet ((call-process-region (&rest args)
(apply 'org-babel-tramp-handle-call-process-region args)))
(flet ((lang-check (f)
(org-flet ((lang-check (f)
(let ((f (intern (concat "org-babel-execute:" f))))
(when (fboundp f) f))))
(setq cmd
@ -618,7 +618,7 @@ arguments and pop open the results in a preview buffer."
(l2 (length s2))
(dist (map 'vector (lambda (_) (make-vector (1+ l2) nil))
(number-sequence 1 (1+ l1)))))
(flet ((in (i j) (aref (aref dist i) j))
(org-flet ((in (i j) (aref (aref dist i) j))
(mmin (&rest lst) (apply #'min (remove nil lst))))
(setf (aref (aref dist 0) 0) 0)
(dolist (i (number-sequence 1 l1))
@ -789,7 +789,7 @@ with a prefix argument then this is passed on to
(defun org-babel-switch-to-session-with-code (&optional arg info)
"Switch to code buffer and display session."
(interactive "P")
(flet ((swap-windows
(org-flet ((swap-windows
()
(let ((other-window-buffer (window-buffer (next-window))))
(set-window-buffer (next-window) (current-buffer))
@ -1017,7 +1017,7 @@ the current subtree."
(setf (nth 2 info)
(sort (copy-sequence (nth 2 info))
(lambda (a b) (string< (car a) (car b)))))
(labels ((rm (lst)
(org-labels ((rm (lst)
(dolist (p '("replace" "silent" "append" "prepend"))
(setq lst (remove p lst)))
lst)
@ -1264,7 +1264,7 @@ ALTS is a cons of two character options where each option may be
either the numeric code of a single character or a list of
character alternatives. For example to split on balanced
instances of \"[ \t]:\" set ALTS to '((32 9) . 58)."
(flet ((matches (ch spec) (if (listp spec) (member ch spec) (equal spec ch)))
(org-flet ((matches (ch spec) (if (listp spec) (member ch spec) (equal spec ch)))
(matched (ch last)
(if (consp alts)
(and (matches ch (cdr alts))
@ -1292,7 +1292,7 @@ instances of \"[ \t]:\" set ALTS to '((32 9) . 58)."
(defun org-babel-join-splits-near-ch (ch list)
"Join splits where \"=\" is on either end of the split."
(flet ((last= (str) (= ch (aref str (1- (length str)))))
(org-flet ((last= (str) (= ch (aref str (1- (length str)))))
(first= (str) (= ch (aref str 0))))
(reverse
(org-reduce (lambda (acc el)
@ -1389,7 +1389,7 @@ names."
Return a cons cell, the `car' of which contains the TABLE less
colnames, and the `cdr' of which contains a list of the column
names. Note: this function removes any hlines in TABLE."
(flet ((trans (table) (apply #'mapcar* #'list table)))
(org-flet ((trans (table) (apply #'mapcar* #'list table)))
(let* ((width (apply 'max
(mapcar (lambda (el) (if (listp el) (length el) 0)) table)))
(table (trans (mapcar (lambda (row)
@ -1826,7 +1826,7 @@ If the path of the link is a file path it is expanded using
(defun org-babel-format-result (result &optional sep)
"Format RESULT for writing to file."
(flet ((echo-res (result)
(org-flet ((echo-res (result)
(if (stringp result) result (format "%S" result))))
(if (listp result)
;; table result
@ -1933,7 +1933,7 @@ code ---- the results are extracted in the syntax of the source
((member "prepend" result-params)))) ; already there
(setq results-switches
(if results-switches (concat " " results-switches) ""))
(flet ((wrap (start finish)
(org-flet ((wrap (start finish)
(goto-char end) (insert (concat finish "\n"))
(goto-char beg) (insert (concat start "\n"))
(goto-char end) (goto-char (point-at-eol))
@ -2058,7 +2058,7 @@ file's directory then expand relative links."
(defun org-babel-examplize-region (beg end &optional results-switches)
"Comment out region using the inline '==' or ': ' org example quote."
(interactive "*r")
(flet ((chars-between (b e)
(org-flet ((chars-between (b e)
(not (string-match "^[\\s]*$" (buffer-substring b e))))
(maybe-cap (str) (if org-babel-capitalize-examplize-region-markers
(upcase str) str)))
@ -2106,7 +2106,7 @@ parameters when merging lists."
(cdr (assoc 'exports org-babel-common-header-args-w-values))))
(variable-index 0)
params results exports tangle noweb cache vars shebang comments padline)
(flet ((e-merge (exclusive-groups &rest result-params)
(org-flet ((e-merge (exclusive-groups &rest result-params)
;; maintain exclusivity of mutually exclusive parameters
(let (output)
(mapc (lambda (new-params)
@ -2218,11 +2218,11 @@ header argument from buffer or subtree wide properties.")
(defun org-babel-noweb-p (params context)
"Check if PARAMS require expansion in CONTEXT.
CONTEXT may be one of :tangle, :export or :eval."
(flet ((intersect (as bs)
(when as
(if (member (car as) bs)
(car as)
(intersect (cdr as) bs)))))
(org-labels ((intersect (as bs)
(when as
(if (member (car as) bs)
(car as)
(intersect (cdr as) bs)))))
(intersect (case context
(:tangle '("yes" "tangle" "no-export" "strip-export"))
(:eval '("yes" "no-export" "strip-export" "eval"))
@ -2267,7 +2267,7 @@ block but are passed literally to the \"example-block\"."
(rx-prefix (concat "\\(" org-babel-src-name-regexp "\\|"
":noweb-ref[ \t]+" "\\)"))
(new-body "") index source-name evaluate prefix blocks-in-buffer)
(flet ((nb-add (text) (setq new-body (concat new-body text)))
(org-flet ((nb-add (text) (setq new-body (concat new-body text)))
(c-wrap (text)
(with-temp-buffer
(funcall (intern (concat lang "-mode")))

View File

@ -309,7 +309,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
(defun org-bibtex-headline ()
"Return a bibtex entry of the given headline as a string."
(flet ((val (key lst) (cdr (assoc key lst)))
(org-flet ((val (key lst) (cdr (assoc key lst)))
(to (string) (intern (concat ":" string)))
(from (key) (substring (symbol-name key) 1))
(flatten (&rest lsts)
@ -406,7 +406,7 @@ This variable is relevant only if `org-bibtex-export-tags-as-keywords` is t."
(defun org-bibtex-fleshout (type &optional optional)
"Fleshout the current heading, ensuring that all required fields are present.
With optional argument OPTIONAL, also prompt for optional fields."
(flet ((val (key lst) (cdr (assoc key lst)))
(org-flet ((val (key lst) (cdr (assoc key lst)))
(keyword (name) (intern (concat ":" (downcase name))))
(name (keyword) (substring (symbol-name keyword) 1)))
(dolist (field (append
@ -600,7 +600,7 @@ With a prefix arg, query for optional fields."
"Read a bibtex entry and save to `org-bibtex-entries'.
This uses `bibtex-parse-entry'."
(interactive)
(flet ((keyword (str) (intern (concat ":" (downcase str))))
(org-flet ((keyword (str) (intern (concat ":" (downcase str))))
(clean-space (str) (replace-regexp-in-string
"[[:space:]\n\r]+" " " str))
(strip-delim (str) ; strip enclosing "..." and {...}
@ -626,7 +626,7 @@ This uses `bibtex-parse-entry'."
(error "No entries in `org-bibtex-entries'."))
(let ((entry (pop org-bibtex-entries))
(org-special-properties nil)) ; avoids errors with `org-entry-put'
(flet ((val (field) (cdr (assoc field entry)))
(org-flet ((val (field) (cdr (assoc field entry)))
(togtag (tag) (org-toggle-tag tag 'on)))
(org-insert-heading)
(insert (val :title))

View File

@ -110,6 +110,16 @@ any other entries, and any resulting duplicates will be removed entirely."
t))
t)))
;;; cl macros no longer available in the trunk
(defalias 'org-flet (if (org-version-check "24.1.50" "cl" :predicate)
'cl-flet*
'flet))
(defalias 'org-labels (if (org-version-check "24.1.50" "cl" :predicate)
'cl-labels
'labels))
;;;; Emacs/XEmacs compatibility
;; Keys

View File

@ -170,7 +170,7 @@ which defaults to the value of `org-export-blocks-witheld'."
(types '())
matched indentation type func
start end body headers preserve-indent progress-marker)
(flet ((interblock (start end)
(org-flet ((interblock (start end)
(mapcar (lambda (pair) (funcall (second pair) start end))
org-export-interblocks)))
(goto-char (point-min))

View File

@ -2734,7 +2734,7 @@ INDENT was the original indentation of the block."
(setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
(cond
((and lang org-export-latex-listings)
(flet ((make-option-string
(org-flet ((make-option-string
(pair)
(concat (first pair)
(if (> (length (second pair)) 0)

View File

@ -58,7 +58,8 @@
(if (or (> emacs-major-version 23)
(and (>= emacs-major-version 23)
(>= emacs-minor-version 2)))
`(with-no-warnings (called-interactively-p ,kind)) ;; defined with no argument in <=23.1
;; defined with no argument in <=23.1
`(with-no-warnings (called-interactively-p ,kind))
`(interactive-p))))
(def-edebug-spec org-called-interactively-p (&optional ("quote" symbolp)))

View File

@ -269,7 +269,7 @@ after the current heading."
For the acceptable UNITS, see `org-timestamp-change'."
(interactive)
(flet ((org-read-date (&rest rest) (current-time)))
(org-flet ((org-read-date (&rest rest) (current-time)))
(org-time-stamp nil))
(when shift
(org-timestamp-change shift units)))
@ -375,7 +375,7 @@ nor a function, elements of KEYWORDS are used directly."
(defun org-mouse-set-priority (priority)
"Set the priority of the current headline to PRIORITY."
(flet ((read-char-exclusive () priority))
(org-flet ((read-char-exclusive () priority))
(org-priority)))
(defvar org-mouse-priority-regexp "\\[#\\([A-Z]\\)\\]"
@ -532,7 +532,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
,@(org-mouse-keyword-menu
(mapcar 'car org-agenda-custom-commands)
#'(lambda (key)
(eval `(flet ((read-char-exclusive () (string-to-char ,key)))
(eval `(org-flet ((read-char-exclusive () (string-to-char ,key)))
(org-agenda nil))))
nil
#'(lambda (key)
@ -625,7 +625,7 @@ This means, between the beginning of line and the point."
(defun org-mouse-context-menu (&optional event)
(let ((stamp-prefixes (list org-deadline-string org-scheduled-string))
(contextlist (org-context)))
(flet ((get-context (context) (org-mouse-get-context contextlist context)))
(org-flet ((get-context (context) (org-mouse-get-context contextlist context)))
(cond
((org-mouse-mark-active)
(let ((region-string (buffer-substring (region-beginning) (region-end))))

View File

@ -160,7 +160,7 @@ and dependant variables."
(with-temp-file data-file
(let ((num-rows (length table)) (num-cols (length (first table)))
front-edge back-edge)
(flet ((gnuplot-row (col row value)
(org-flet ((gnuplot-row (col row value)
(setf col (+ 1 col)) (setf row (+ 1 row))
(format "%f %f %f\n%f %f %f\n"
col (- row 0.5) value ;; lower edge
@ -209,7 +209,7 @@ manner suitable for prepending to a user-specified script."
('3d "splot")
('grid "splot")))
(script "reset") plot-lines)
(flet ((add-to-script (line) (setf script (format "%s\n%s" script line))))
(org-flet ((add-to-script (line) (setf script (format "%s\n%s" script line))))
(when file ;; output file
(add-to-script (format "set term %s" (file-name-extension file)))
(add-to-script (format "set output '%s'" file)))

View File

@ -14342,7 +14342,7 @@ when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
(assoc property org-global-properties)
(assoc property org-global-properties-fixed))))
val)
(flet ((ap (key)
(org-flet ((ap (key)
(when (re-search-forward
(org-re-property key) (cdr range) t)
(setq props
@ -20787,7 +20787,7 @@ the functionality can be provided as a fall-back.")
(throw 'exit nil))))))
;; Use `fill-paragraph' with buffer narrowed to item
;; without any child, and with our computed PREFIX.
(flet ((fill-context-prefix (from to &optional flr) prefix))
(org-flet ((fill-context-prefix (from to &optional flr) prefix))
(save-restriction
(narrow-to-region beg end)
(save-excursion (fill-paragraph justify)))) t))
@ -20858,7 +20858,7 @@ the functionality can be provided as a fall-back.")
(cond ((setq itemp (org-in-item-p))
(progn
(setq prefix (make-string (org-list-item-body-column itemp) ?\ ))
(flet ((fill-context-prefix (from to &optional flr) prefix))
(org-flet ((fill-context-prefix (from to &optional flr) prefix))
(do-auto-fill))))
(orgstruct-is-++
(org-let org-fb-vars