Emacs键盘宏无法调用组织模式捕获模板

时间:2015-01-10 01:50:32

标签: emacs org-mode

我正在尝试使用以下键盘测试宏

(fset 'jj   [?\C-c ?c ?t ?j ?j  return ?\C-c ?\C-c]) 

调用此捕获模板定义

(setq org-capture-templates '(("t" "Todo" entry (file "~/org/j.org"))))

请注意C-c c调用 M-x org-capture

不幸的是,它会产生以下错误消息:

After 0 kbd macro
iterations: byte-code: Capture abort: (wrong-type-argument stringp
(file:~/org/todo.org::*Tasks Tasks))

我制作了下面的回溯节目。组织模式配置是 追溯后追加。

Debugger entered--Lisp error: 
(error "Capture abort: (wrong-type-argument stringp
(file:~/org/todo.org::*Tasks Tasks))")

signal(error ("Capture abort: (wrong-type-argument stringp
(file:~/org/todo.org::*Tasks Tasks))"))

error("Capture abort: %s" (wrong-type-argument stringp
("file:~/org/todo.org::*Tasks" "Tasks")))

(condition-case error (org-capture-put :template
(org-capture-fill-template)) ((error quit) (if (get-buffer "*Capture*")
(kill-buffer "*Capture*")) (error "Capture abort: %s" error)))

 (cond ((equal entry "C") (customize-variable (quote org-capture-templates))) 
  ((equal entry "q") (error "Abort")) 
  (t (org-capture-set-plist entry) (org-capture-get-template) 
     (org-capture-put :original-buffer orig-buf 
                      :original-file (or (buffer-file-name orig-buf) 
                                         (and (featurep (quote dired)) 
                                              (car (rassq orig-buf
                                                         dired-buffers))))
                      :original-file-nondirectory (and (buffer-file-name
                                                      orig-buf) (file-name-nondirectory

        (buffer-file-name orig-buf)))
                      :annotation annotation :initial initial
:return-to-wconf (current-window-configuration)
                      :default-time (or org-overriding-default-time
 (org-current-time))$) 
     (org-capture-set-target-location) 
     (condition-case error
         (org-capture-put :template (org-capture-fill-template))
       ((error quit) 
        (if (get-buffer "*Capture*") (kill-buffer "*Capture*")) 
        (error "Capture abort: %s" error))) 
     (setq org-capture-clock-keep (org-capture-get :clock-keep)) 
     (if (equal goto 0) 
         (org-capture-insert-template-here) 
       (condition-case error 
           (org-capture-place-template 
            (equal (car (org-capture-get :target)) (quote function))) 
         ((error quit) (if (and (buffer-base-buffer ...) 
                                (string-match "\\`CAPTURE-" ...)) 
                           (kill-buffer (current-buffer))) 
          (set-window-configuration (org-capture-get :return-to-wconf)) 
          (error "Capture template `%s': %s" (org-capture-get :key) (nth
                                                           1 error)))) 
       (if (and (derived-mode-p (quote org-mode))
                (org-capture-get :clock-in)) 
           (condition-case nil (progn (if (org-clock-is-active) 
                                          (org-capture-put 
                                           :interrupted-clock...)) 
                                      (org-clock-in) (org-set-local
(quote org-capture-clock-was-started) t)) 
             (error "Could not start the clock in this capture buffer"))) 
       (if (org-capture-get :immediate-finish) (org-capture-finalize)))))

(let* ((orig-buf (current-buffer)) 
   (annotation 
    (if (and (boundp (quote org-capture-link-is-already-stored))
             org-capture-link-is-already-stored) 
        (plist-get org-store-link-plist :annotation) 
      (condition-case nil (progn (org-store-link nil)) 
        (error nil)))) 
   (entry (or org-capture-entry (org-capture-select-template keys)))
         initial) 
 (setq initial (or org-capture-initial (and (org-region-active-p)
 (buffer-substring (point) (mark))))) 
 (if (stringp initial) (progn (remove-text-properties 0 (length initial)
 (quote (read-only t)) initial))) 
 (if (stringp annotation) (progn (remove-text-properties 0 (length annotation) 
   (quote (read-only  t)) annotation))) 
 (cond ((equal entry "C")
     (customize-variable (quote org-capture-templates))) 
    ((equal entry "q") 
     (error "Abort")) (t (org-capture-set-plist entry)
                         (org-capture-get-template) 
                         (org-capture-put 
                          :original-buffer orig-buf
                          :original-file (or (buffer-file-name orig-buf)
                                             (and (featurep (quote dired)) 
                                                  (car (rassq orig-buf
                                          dired-buffers)))) 
                          :original-file-nondirectory (and
                              (buffer-file-name orig-buf)

  (file-name-nondirectory

            (buffer-file-name orig-buf))) 
                          :annotation annotation :initial initial
                       :return-to-wconf
                          (current-window-configuration) 
                          :default-time (or org-overriding-default-time
        (org-current-time)))
                         (org-capture-set-target-location) 
                         (condition-case error 
                             (org-capture-put :template
          (org-capture-fill-template))
                           ((error quit) 
                            (if (get-buffer "*Capture*") 
                                (kill-buffer "*Capture*")) 
                            (error "Capture abort: %s" error))) 
                         (setq org-capture-clock-keep (org-capture-get
              :clock-keep)) 
                         (if (equal goto 0) 
 (org-capture-insert-template-here) 
                           (condition-case error
 (org-capture-place-template (equal (car ...) (quote function))) 
                             ((error quit) (if (and ... ...)
                                               (kill-buffer ...)) 
                              (set-window-configuration (org-capture-get
    :return-to-wconf)) 
                              (error "Capture template `%s': %s"
(org-capture-get :key) (nth 1 error)))) 
                           (if (and (derived-mode-p (quote org-mode))
(org-capture-get :clock-in))
                               (condition-case nil (progn (if ... ...)
(org-clock-in) (org-set-local ... t)) 
                                 (error "Could not start the clock in
               this capture buffer"))) 
                           (if (org-capture-get :immediate-finish)
(org-capture-finalize))))))                    
(cond ((equal goto (quote (4))) (org-capture-goto-target)) 
  ((equal goto (quote (16))) (org-capture-goto-last-stored))
  (t (let* ((orig-buf (current-buffer)) 
            (annotation (if (and (boundp ...)
org-capture-link-is-already-stored) 
                            (plist-get org-store-link-plist :annotation) 
                          (condition-case nil (progn ...) (error nil)))) 
            (entry (or org-capture-entry
                       (org-capture-select-template keys))) initial) 
       (setq initial (or org-capture-initial 
                         (and (org-region-active-p)
                              (buffer-substring (point) (mark))))) 
       (if (stringp initial) 
           (progn
             (remove-text-properties 0 (length initial) 
                                     (quote (read-only t)) initial))) 
       (if (stringp annotation)
           (progn (remove-text-properties 0 (length annotation) 
                                          (quote (read-only t))
annotation))) 
       (cond ((equal entry "C") (customize-variable (quote
 org-capture-templates))) 
             ((equal entry "q") 
              (error "Abort")) 
             (t (org-capture-set-plist entry) (org-capture-get-template) 
                (org-capture-put 
                 :original-buffer orig-buf 
                 :original-file (or (buffer-file-name orig-buf) (and ...
...)) 
                 :original-file-nondirectory (and (buffer-file-name
orig-buf) (file-name-nondirectory ...)) 
                 :annotation annotation 
                 :initial initial 
                 :return-to-wconf (current-window-configuration) 
                 :default-time (or org-overriding-default-time
(org-current-time)))
                (org-capture-set-target-location) 
                (condition-case error (org-capture-put 
                                       :template
(org-capture-fill-template))
                  ((error quit) (if ... ...) 
                   (error "Capture abort: %s" error))) 
                (setq org-capture-clock-keep
                      (org-capture-get :clock-keep)) 
                (if (equal goto 0)
                    (org-capture-insert-template-here) 
                  (condition-case error (org-capture-place-template ...)
                    (... ... ... ...)) 
                  (if (and ... ...) (condition-case nil ... ...)) 
                  (if (org-capture-get :immediate-finish)
                      (org-capture-finalize))))))))                
org-capture(nil)
call-interactively(org-capture nil nil)
command-execute(jj record)
execute-extended-command(nil "jj")
call-interactively(execute-extended-command nil nil)
----------------------------------------------------
ORG-MODE CONFIGURATION
Emacs  : GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.4.2)
      of 2014-02-22 on chindi10, modified by Debian
Package: Org-mode version 8.2.10 (8.2.10-dist  <at>  /usr/share/emacs/site-lisp/org/)

 current state:
==============
(setq
 org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point
 org-babel-execute-safely-maybe)
 org-tab-first-hook '(org-hide-block-toggle-maybe
 org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe
 org-babel-header-arg-expand)
 org-agenda-use-time-grid nil
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
 org-cycle-hide-inline-tasks org-cycle-show-empty-lines
 org-optimize-window-after-visibility-change)
 org-agenda-custom-commands '(("pa" "A-priority" tags-todo
 "+SCHEDULED<=\"<today>\"+PRIORITY=\"A\"") ("pb" "B-priority"

                      tags-todo

                      "+SCHEDULED<=\"<today>\"+PRIORITY=\"B\"")
                          ("pc" "C-priority" tags-todo
 "+SCHEDULED<=\"<today>\"+PRIORITY=\"C\"") ("b" "Buy" tags

                      "+CATEGORY=\"BUY\"")
                          ("w" "Web" tags "+CATEGORY=\"WEB\"") ("k"
 "Books" tags "+CATEGORY=\"BOOKS\"")
                          ("v" "Movies" tags "+CATEGORY=\"MOVIES\"")
 ("u" "Music" tags "+CATEGORY=\"MUSIC\""))
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-speed-command-hook '(org-speed-command-default-hook
 org-babel-speed-command-hook)
 org-babel-pre-tangle-hook '(save-buffer)
 org-occur-hook '(org-first-headline-recenter)
 org-deadline-warning-days 0
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-capture-templates '(("t" "Todo" entry (file "~/org/j.org")))
 org-agenda-sorting-strategy '((agenda priority-down) (todo priority-down
 category-keep) (tags priority-down category-keep) (search category-keep))
 org-agenda-start-with-follow-mode t
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-agenda-prefix-format "  %-11:c% s"
 org-mode-hook '(#[nil "\300\301\302\303\304$\207" [org-add-hook
 change-major-mode-hook org-show-block-all append local]
               5]
             #[nil "\300\301\302\303\304$\207" [org-add-hook
 change-major-mode-hook org-babel-show-result-all append local] 5]
 org-babel-result-hide-spec org-babel-hide-all-hashes my-org-mode-hook)
 org-agenda-start-on-weekday nil
 org-agenda-mode-hook '(my-org-agenda-mode-hook)
 org-directory "~/org/"
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-agenda-files '("~/org/todo.org" "~/org/home.org")
 org-src-mode-hook '(org-src-babel-configure-edit-buffer
 org-src-mode-configure-edit-buffer)
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-confirm-shell-link-function 'yes-or-no-p
 )

1 个答案:

答案 0 :(得分:1)

简短:executing-kbd-macro中的org-store-link是原因。我无法想出一个简单的解决方案。

我尝试重现此错误并找到了该功能

(defun test-inside-kbd-macro ()
  (interactive)
  (print (ignore-errors (org-store-link nil))))

根据运行方式给出不同的结果。 1)M-x test-inside-kbd-macro 给出"[[file:~/git/org/refile.org::*kbd%20capture][kbd capture]]"(字符串),但是2)

(execute-kbd-macro (read-kbd-macro "M-x test-inside-kbd-macro RET"))

给出("file:~/git/org/refile.org::*kbd capture" "kbd capture")(列表)。因此,错误(wrong-type-argument stringp ...)就会发生。

如果看到函数org-store-link的代码(最后10行)

;; Return the link
(if (not (and (or (org-called-interactively-p 'any)
         executing-kbd-macro) link))
   (or agenda-link (and link (org-make-link-string link desc)))
 (push (list link desc) org-stored-links)
 (message "Stored: %s" (or desc link))
 (when custom-id
   (setq link (concat "file:" (abbreviate-file-name
                   (buffer-file-name)) "::#" custom-id))
   (push (list link desc) org-stored-links))
 (car org-stored-links))))))

你会发现在1)情况下,函数test-inside-kbd-macro的值是使用(org-make-link-string link desc)创建的,在2)情况下是使用(car org-stored-links)

我认为这是由于executing-kbd-macro部分中的if


ORG-捕获:

注释 - &gt; (ignore-errors(org-store-link nil))

(org-capture-put ...  :注释注释...)

ORG-捕获 - 填充 - 模板:

(v-a (or (plist-get org-store-link-plist :annotation)
      annotation
      (org-capture-get :annotation)
      ""))

(v-A (if (and v-a (string-match l-re v-a))

生成错误。