From 8687829d88513dd4af0eb254a0e0b0a28f4263d0 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 18 Jul 2012 07:35:46 -0600 Subject: [PATCH] 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/ob-awk.el | 2 +- lisp/ob-comint.el | 2 +- lisp/ob-exp.el | 2 +- lisp/ob-gnuplot.el | 2 +- lisp/ob-lob.el | 4 ++-- lisp/ob-python.el | 2 +- lisp/ob-ref.el | 2 +- lisp/ob-sh.el | 2 +- lisp/ob-tangle.el | 6 +++--- lisp/ob.el | 30 +++++++++++++++--------------- lisp/org-bibtex.el | 8 ++++---- lisp/org-exp-blocks.el | 2 +- lisp/org-exp.el | 2 +- lisp/org-macs.el | 25 ++++++++++++++++++++++++- lisp/org-mouse.el | 8 ++++---- lisp/org-odt.el | 4 ++-- lisp/org-plot.el | 4 ++-- lisp/org.el | 6 +++--- 18 files changed, 68 insertions(+), 45 deletions(-) diff --git a/lisp/ob-awk.el b/lisp/ob-awk.el index 682d802..f89f775 100644 --- a/lisp/ob-awk.el +++ b/lisp/ob-awk.el @@ -96,7 +96,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))) diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el index a0712b9..a560401 100644 --- a/lisp/ob-comint.el +++ b/lisp/ob-comint.el @@ -74,7 +74,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) diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 561d5f3..5c52ee2 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -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)))) diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index 5d07366..0f84643 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -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 diff --git a/lisp/ob-lob.el b/lisp/ob-lob.el index 1c0cf04..ab56d9e 100644 --- a/lisp/ob-lob.el +++ b/lisp/ob-lob.el @@ -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) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 348248f..3f4273c 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -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 diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 08cb4e3..6180e0b 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -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 diff --git a/lisp/ob-sh.el b/lisp/ob-sh.el index 1fbac1d..0d0c829 100644 --- a/lisp/ob-sh.el +++ b/lisp/ob-sh.el @@ -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))) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 2af033c..74ebddf 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -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")) diff --git a/lisp/ob.el b/lisp/ob.el index 98ad40f..5c44835 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -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,7 +2218,7 @@ 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) + (org-flet ((intersect (as bs) (when as (if (member (car as) bs) (car as) @@ -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"))) diff --git a/lisp/org-bibtex.el b/lisp/org-bibtex.el index dfc1afe..b6f7d7e 100644 --- a/lisp/org-bibtex.el +++ b/lisp/org-bibtex.el @@ -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)) diff --git a/lisp/org-exp-blocks.el b/lisp/org-exp-blocks.el index 3861bc3..fba7e03 100644 --- a/lisp/org-exp-blocks.el +++ b/lisp/org-exp-blocks.el @@ -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)) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index d1084d7..8d4ed4d 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -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) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 1c25249..0c0efaf 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -45,6 +45,28 @@ (declare-function org-add-props "org-compat" (string plist &rest props)) (declare-function org-string-match-p "org-compat" (&rest args)) +;; emacs-version +;; 24 -> "24.1.1" +;; trunk -> "24.1.50.3" +(defun org-emacs-full-version () + (mapcar #'string-to-number (split-string emacs-version "\\."))) + +(defalias 'org-flet (if (or (> emacs-major-version 24) + (and (= emacs-major-version 24) + (let ((full (org-emacs-full-version))) + (and (third full) + (> (third full) 1))))) + 'cl-flet + 'flet)) + +(defalias 'org-labels (if (or (> emacs-major-version 24) + (and (= emacs-major-version 24) + (let ((full (org-emacs-full-version))) + (and (third full) + (> (third full) 1))))) + 'cl-labels + 'labels)) + (defmacro org-with-gensyms (symbols &rest body) `(let ,(mapcar (lambda (s) `(,s (make-symbol (concat "--" (symbol-name ',s))))) symbols) @@ -58,7 +80,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))) diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el index 57e9575..81e4724 100644 --- a/lisp/org-mouse.el +++ b/lisp/org-mouse.el @@ -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)))) diff --git a/lisp/org-odt.el b/lisp/org-odt.el index e24c8a5..2b52c87 100644 --- a/lisp/org-odt.el +++ b/lisp/org-odt.el @@ -2033,8 +2033,8 @@ ATTR is a string of other attributes of the a element." (defun org-odt-do-image-size (probe-method file &optional dpi anchor-type) (setq dpi (or dpi org-export-odt-pixels-per-inch)) (setq anchor-type (or anchor-type "paragraph")) - (flet ((size-in-cms (size-in-pixels) - (flet ((pixels-to-cms (pixels) + (org-flet ((size-in-cms (size-in-pixels) + (org-flet ((pixels-to-cms (pixels) (let* ((cms-per-inch 2.54) (inches (/ pixels dpi))) (* cms-per-inch inches)))) diff --git a/lisp/org-plot.el b/lisp/org-plot.el index f44694f..0f3e18b 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -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))) diff --git a/lisp/org.el b/lisp/org.el index 4241168..575fb7c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -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 -- 1.7.11.2