org-mode can't edit C source code - emacs

When I use emacs's org-mode to edit a C program, that is when I edit the below segment:
#+begin_src c
#define MAX 100
#+end_src
and after I call the function 'org-edit-src-code' to edit the C code in a new buffer, there is an error:
Language mode `c-mode' fails with: stringp
and I can neither save to nor return to the original buffer after I edit the code in the new buffer.
Every other languages can work without any problem, including C++, elisp, sh.
How can I fix this problem? My org-mode version is 7.6 and emacs version is 23.2.
the full debug info is (follow Noufal Ibrahim's method):
Debugger entered--Lisp error: (error "Language mode `c-mode' fails with: stringp")
signal(error ("Language mode `c-mode' fails with: stringp"))
error("Language mode `%s' fails with: %S" c-mode stringp)
(condition-case e (funcall lang-f) (error (error "Language mode `%s' fails with: %S" lang-f ...)))
(let ((org-inhibit-startup t)) (condition-case e (funcall lang-f) (error ...)))
(if (and (setq buffer ...) (if org-src-ask-before-returning-to-edit-buffer ... t)) (org-src-switch-to-buffer buffer (quote return)) (when buffer (with-current-buffer buffer ...) (kill-buffer buffer)) (setq buffer (generate-new-buffer ...)) (setq ovl (make-overlay beg end)) (overlay-put ovl (quote edit-buffer) buffer) (overlay-put ovl (quote help-echo) "Click with mouse-1 to switch to buffer editing this segment") (overlay-put ovl (quote face) (quote secondary-selection)) (overlay-put ovl (quote keymap) (let ... ... map)) (overlay-put ovl :read-only "Leave me alone") (setq transmitted-variables (append transmitted-variables ...)) (org-src-switch-to-buffer buffer (quote edit)) (if (eq single ...) (setq code ...)) (insert code) (remove-text-properties (point-min) (point-max) (quote ...)) (unless (cadr ...) (setq total-nindent ...)) (let (...) (condition-case e ... ...)) (dolist (pair transmitted-variables) (org-set-local ... ...)) (when org-mode-p (goto-char ...) (while ... ... ...)) (when markline (org-goto-line ...) (org-move-to-column ...) (push-mark ... ... t) (setq deactivate-mark nil)) (org-goto-line (1+ ...)) (org-move-to-column (if org-src-preserve-indentation col ...)) (org-src-mode) (set-buffer-modified-p nil) (and org-edit-src-persistent-message (org-set-local ... msg)) (let (...) (when ... ...)))
(if (not info) nil (setq beg (move-marker beg ...) end (move-marker end ...) msg (if allow-write-back-p ... "Exit with C-c ' (C-c and single quote)") code (or code ...) lang (or ... ...) lang (if ... ... lang) single (nth 3 info) block-nindent (nth 5 info) lang-f (intern ...) begline (save-excursion ... ...) transmitted-variables (\` ...)) (if (and mark ... ...) (save-excursion ... ...)) (if (equal lang-f ...) (setq lang-f ...)) (unless (functionp lang-f) (error "No such language mode: %s" lang-f)) (save-excursion (if ... ...) (setq line ... col ...)) (if (and ... ...) (org-src-switch-to-buffer buffer ...) (when buffer ... ...) (setq buffer ...) (setq ovl ...) (overlay-put ovl ... buffer) (overlay-put ovl ... "Click with mouse-1 to switch to buffer editing this segment") (overlay-put ovl ... ...) (overlay-put ovl ... ...) (overlay-put ovl :read-only "Leave me alone") (setq transmitted-variables ...) (org-src-switch-to-buffer buffer ...) (if ... ...) (insert code) (remove-text-properties ... ... ...) (unless ... ...) (let ... ...) (dolist ... ...) (when org-mode-p ... ...) (when markline ... ... ... ...) (org-goto-line ...) (org-move-to-column ...) (org-src-mode) (set-buffer-modified-p nil) (and org-edit-src-persistent-message ...) (let ... ...)) t)
(let ((mark ...) (case-fold-search t) (info ...) (full-info ...) (org-mode-p ...) (beg ...) (end ...) (allow-write-back-p ...) block-nindent total-nindent ovl lang lang-f single lfmt buffer msg begline markline markcol line col transmitted-variables) (if (not info) nil (setq beg ... end ... msg ... code ... lang ... lang ... single ... block-nindent ... lang-f ... begline ... transmitted-variables ...) (if ... ...) (if ... ...) (unless ... ...) (save-excursion ... ...) (if ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) t))
org-edit-src-code()
(cond ((save-excursion ... ...) (find-file ...)) ((org-edit-src-code)) ((org-edit-fixed-width-region)) ((org-at-table\.el-p) (org-edit-src-code)) ((or ... ...) (call-interactively ...)) (t (call-interactively ...)))
org-edit-special()
call-interactively(org-edit-special nil nil)
I am a novice and I don't know what the problem is. Any advice?

As discovered in the comments this is caused by accessing buffer-file-name in a temporary buffer which is not backed by a file and hence buffer-file-name is nil giving rise the it's failing stringp. Anyway, one way to fix it is by replacing instances of buffer-file-name with
(or buffer-file-name "DEFAULT-NAME")
if you need to use it, or by a block like the following
(when buffer-file-name
(code-going-here-will-only-be-executed-if-buffer-file-name-in-non-nil))
Which is easier/better will of course depend upon what you are doing.

Related

Emacs keyboard macro fails to invoke org-mode capture template

I am trying to use the following keyboard test macro
(fset 'jj [?\C-c ?c ?t ?j ?j return ?\C-c ?\C-c])
to invoke this capture template definition
(setq org-capture-templates '(("t" "Todo" entry (file "~/org/j.org"))))
Note that C-c c invokes M-x org-capture.
Unfortunately, it produces the following error message:
After 0 kbd macro
iterations: byte-code: Capture abort: (wrong-type-argument stringp
(file:~/org/todo.org::*Tasks Tasks))
I have produced the backtrace show below. The org-mode configuration is
appended after the backtrace.
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
)
Short: executing-kbd-macro in org-store-link is the reason. I couldn't come up with a simple solution.
I tried to reproduce this error and found that function
(defun test-inside-kbd-macro ()
(interactive)
(print (ignore-errors (org-store-link nil))))
gives different results depending on way to run. 1) M-x test-inside-kbd-macro
gives "[[file:~/git/org/refile.org::*kbd%20capture][kbd capture]]" (string), but 2)
(execute-kbd-macro (read-kbd-macro "M-x test-inside-kbd-macro RET"))
gives ("file:~/git/org/refile.org::*kbd capture" "kbd capture") (list). So the error (wrong-type-argument stringp ...) occurs due to this.
If you see code of the function org-store-link(the last 10 lines)
;; 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))))))
you will find that in the 1) case the value of the function test-inside-kbd-macro is created using (org-make-link-string link desc) and in the 2) case - using (car org-stored-links).
I think this is due to executing-kbd-macro in if section.
org-capture:
annotation -> (ignore-errors (org-store-link nil))
(org-capture-put ...
:annotation annotation ...)
org-capture-fill-template:
(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))
generates the error.

Emacs tramp "Wrong type argument listp" error

The title sounds almost identical to the question here. It didn't seem to be resolved and I couldn't post a comment and hence opened up this question.
I am using emacs 24.3.1 installed using MacPorts on a Mac OS X Mavericks. I have been using tramp to access remote files without a problem until recently. I used to ssh without my username to access the files and it worked fine. When it stopped working, I noticed the error "Wrong type argument: listp, /home/t_nithyanandan/.bashrc" and this problem is not specific to .bashrc. It happens for any file. Subsequently I started putting my username in the ssh line in front of the remote machine name and it was working for a while until it broke down too with the same error. Now I am unable to use tramp at all.
I am able to open my files on my local machine without trouble using C-x C-f. I reinstalled emacs using macports but it doesn't change anything. I installed emacs from here but it has the same problem while using tramp.
I disabled my .emacs before startup but that doesn't help either.
After doing
M-x load-library RET tramp.el RET
C-u 1 M-x toggle-debug-on-error RET
Here's the output in *Messages*:
Loading /opt/local/share/emacs/site-lisp/subdirs.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...
Loading /Applications/MacPorts/Emacs.app/Contents/Resources/lisp/net/tramp.el.gz...
uncompressing tramp.el.gz...done
Loading /Applications/MacPorts/Emacs.app/Contents/Resources/lisp/net/tramp.el.gz...done
Debug on Error enabled globally
Quit
Tramp: Opening connection for enterprise.sese.asu.edu using ssh...
Tramp: Sending command `exec ssh -e none enterprise.sese.asu.edu'
Tramp: Waiting for prompts from remote shell
Tramp: Sending password
Tramp: Sending command `exec ssh -e none enterprise.sese.asu.edu'
Tramp: Found remote shell prompt on `enterprise.sese.asu.edu'
Tramp: Opening connection for enterprise.sese.asu.edu using ssh...done
Entering debugger...
Tramp: Opening connection for enterprise.sese.asu.edu using ssh...
Tramp: Sending command `exec ssh -e none enterprise.sese.asu.edu'
Tramp: Waiting for prompts from remote shell
Tramp: Sending password
Tramp: Sending command `exec ssh -e none enterprise.sese.asu.edu'
Tramp: Found remote shell prompt on `enterprise.sese.asu.edu'
Tramp: Opening connection for enterprise.sese.asu.edu using ssh...done
tramp-sh-handle-file-attributes: Wrong type argument: listp, /home/t_nithyanandan/\.bashrc
Here's the output of *Backtrace*:
Debugger entered--Lisp error: (wrong-type-argument listp /home/t_nithyanandan/\.bashrc)
tramp-convert-file-attributes(["ssh" nil "enterprise.sese.asu.edu" "/home/t_nithyanandan/.bashrc" nil] /home/t_nithyanandan/\.bashrc)
tramp-sh-handle-file-attributes("/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc")
apply(tramp-sh-handle-file-attributes "/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc")
tramp-sh-file-name-handler(file-attributes "/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc")
apply(tramp-sh-file-name-handler file-attributes "/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc")
(catch (quote suppress) (apply foreign operation args))
(catch (quote non-essential) (catch (quote suppress) (apply foreign operation args)))
(setq result (catch (quote non-essential) (catch (quote suppress) (apply foreign operation args))))
(let ((sf (symbol-function foreign)) result) (if (and (listp sf) (eq (car sf) (quote autoload))) (progn (let ((default-directory (tramp-compat-temporary-file-directory))) (load (cadr sf) (quote noerror) (quote nomessage))))) (setq result (catch (quote non-essential) (catch (quote suppress) (apply foreign operation args)))) (cond ((eq result (quote non-essential)) (tramp-message v 5 "Non-essential received in operation %s" (append (list operation) args)) (tramp-run-real-handler operation args)) ((eq result (quote suppress)) (let (tramp-message-show-message) (tramp-message v 1 "Suppress received in operation %s" (append (list operation) args)) (tramp-cleanup v) (tramp-run-real-handler operation args))) (t result)))
(lambda nil (let ((sf (symbol-function foreign)) result) (if (and (listp sf) (eq (car sf) (quote autoload))) (progn (let ((default-directory (tramp-compat-temporary-file-directory))) (load (cadr sf) (quote noerror) (quote nomessage))))) (setq result (catch (quote non-essential) (catch (quote suppress) (apply foreign operation args)))) (cond ((eq result (quote non-essential)) (tramp-message v 5 "Non-essential received in operation %s" (append (list operation) args)) (tramp-run-real-handler operation args)) ((eq result (quote suppress)) (let (tramp-message-show-message) (tramp-message v 1 "Suppress received in operation %s" (append (list operation) args)) (tramp-cleanup v) (tramp-run-real-handler operation args))) (t result))))()
funcall((lambda nil (let ((sf (symbol-function foreign)) result) (if (and (listp sf) (eq (car sf) (quote autoload))) (progn (let ((default-directory (tramp-compat-temporary-file-directory))) (load (cadr sf) (quote noerror) (quote nomessage))))) (setq result (catch (quote non-essential) (catch (quote suppress) (apply foreign operation args)))) (cond ((eq result (quote non-essential)) (tramp-message v 5 "Non-essential received in operation %s" (append (list operation) args)) (tramp-run-real-handler operation args)) ((eq result (quote suppress)) (let (tramp-message-show-message) (tramp-message v 1 "Suppress received in operation %s" (append (list operation) args)) (tramp-cleanup v) (tramp-run-real-handler operation args))) (t result)))))
(if debug-on-error (funcall body) (condition-case err (funcall body) ((debug quit) (let (tramp-message-show-message) (tramp-message v 1 "Interrupt received in operation %s" (append (list operation) args))) (signal (car err) (cdr err))) (error (cond ((and completion (zerop (length localname)) (memq operation (quote ...))) t) ((and completion (zerop (length localname)) (memq operation (quote ...))) filename) (t (signal (car err) (cdr err)))))))
(let ((body (function (lambda nil (let ((sf ...) result) (if (and ... ...) (progn ...)) (setq result (catch ... ...)) (cond (... ... ...) (... ...) (t result))))))) (if debug-on-error (funcall body) (condition-case err (funcall body) ((debug quit) (let (tramp-message-show-message) (tramp-message v 1 "Interrupt received in operation %s" (append (list operation) args))) (signal (car err) (cdr err))) (error (cond ((and completion (zerop ...) (memq operation ...)) t) ((and completion (zerop ...) (memq operation ...)) filename) (t (signal (car err) (cdr err))))))))
(if foreign (let ((body (function (lambda nil (let (... result) (if ... ...) (setq result ...) (cond ... ... ...)))))) (if debug-on-error (funcall body) (condition-case err (funcall body) ((debug quit) (let (tramp-message-show-message) (tramp-message v 1 "Interrupt received in operation %s" (append ... args))) (signal (car err) (cdr err))) (error (cond ((and completion ... ...) t) ((and completion ... ...) filename) (t (signal ... ...))))))) (tramp-run-real-handler operation args))
(let* ((v (tramp-dissect-file-name filename)) (method (tramp-file-name-method v)) (user (tramp-file-name-user v)) (host (tramp-file-name-host v)) (localname (tramp-file-name-localname v)) (hop (tramp-file-name-hop v))) (if foreign (let ((body (function (lambda nil (let ... ... ... ...))))) (if debug-on-error (funcall body) (condition-case err (funcall body) ((debug quit) (let (tramp-message-show-message) (tramp-message v 1 "Interrupt received in operation %s" ...)) (signal (car err) (cdr err))) (error (cond (... t) (... filename) (t ...)))))) (tramp-run-real-handler operation args)))
(let* ((filename (tramp-replace-environment-variables (apply (quote tramp-file-name-for-operation) operation args))) (completion (tramp-completion-mode-p)) (foreign (tramp-find-foreign-file-name-handler filename))) (let* ((v (tramp-dissect-file-name filename)) (method (tramp-file-name-method v)) (user (tramp-file-name-user v)) (host (tramp-file-name-host v)) (localname (tramp-file-name-localname v)) (hop (tramp-file-name-hop v))) (if foreign (let ((body (function (lambda nil ...)))) (if debug-on-error (funcall body) (condition-case err (funcall body) ((debug quit) (let ... ...) (signal ... ...)) (error (cond ... ... ...))))) (tramp-run-real-handler operation args))))
(progn (let* ((filename (tramp-replace-environment-variables (apply (quote tramp-file-name-for-operation) operation args))) (completion (tramp-completion-mode-p)) (foreign (tramp-find-foreign-file-name-handler filename))) (let* ((v (tramp-dissect-file-name filename)) (method (tramp-file-name-method v)) (user (tramp-file-name-user v)) (host (tramp-file-name-host v)) (localname (tramp-file-name-localname v)) (hop (tramp-file-name-hop v))) (if foreign (let ((body (function ...))) (if debug-on-error (funcall body) (condition-case err (funcall body) (... ... ...) (error ...)))) (tramp-run-real-handler operation args)))))
(unwind-protect (progn (let* ((filename (tramp-replace-environment-variables (apply (quote tramp-file-name-for-operation) operation args))) (completion (tramp-completion-mode-p)) (foreign (tramp-find-foreign-file-name-handler filename))) (let* ((v (tramp-dissect-file-name filename)) (method (tramp-file-name-method v)) (user (tramp-file-name-user v)) (host (tramp-file-name-host v)) (localname (tramp-file-name-localname v)) (hop (tramp-file-name-hop v))) (if foreign (let ((body ...)) (if debug-on-error (funcall body) (condition-case err ... ... ...))) (tramp-run-real-handler operation args))))) (set-match-data save-match-data-internal (quote evaporate)))
(let ((save-match-data-internal (match-data))) (unwind-protect (progn (let* ((filename (tramp-replace-environment-variables (apply ... operation args))) (completion (tramp-completion-mode-p)) (foreign (tramp-find-foreign-file-name-handler filename))) (let* ((v (tramp-dissect-file-name filename)) (method (tramp-file-name-method v)) (user (tramp-file-name-user v)) (host (tramp-file-name-host v)) (localname (tramp-file-name-localname v)) (hop (tramp-file-name-hop v))) (if foreign (let (...) (if debug-on-error ... ...)) (tramp-run-real-handler operation args))))) (set-match-data save-match-data-internal (quote evaporate))))
(if tramp-mode (let ((save-match-data-internal (match-data))) (unwind-protect (progn (let* ((filename (tramp-replace-environment-variables ...)) (completion (tramp-completion-mode-p)) (foreign (tramp-find-foreign-file-name-handler filename))) (let* ((v ...) (method ...) (user ...) (host ...) (localname ...) (hop ...)) (if foreign (let ... ...) (tramp-run-real-handler operation args))))) (set-match-data save-match-data-internal (quote evaporate)))) (tramp-run-real-handler operation args))
tramp-file-name-handler(file-attributes "/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc")
file-attributes("/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc")
find-file-noselect("/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc" nil nil t)
find-file("/ssh:enterprise.sese.asu.edu:/home/t_nithyanandan/.bashrc" t)
call-interactively(find-file nil nil)
I am not very good at lisp. If you'd like me to run some diagnostics, please keep in mind that I am a beginner. Any help will be appreciated.
Thanks.
P.S: I must mention that while tramp was working before this break down, there were times when it used to hang and I used C-g impatiently to quit whatever tramp was attempting to do. I am not sure if this could have corrupted something inside tramp.
Edit 1
Trying to follow Drew's advice, here's what I found. I have renamed my init file .emacs to .emacs.bkp and I have been assuming this should disable emacs loading up that init file. Interestingly, if I opened emacs with
emacs -Q
then I am able to ssh into the remote machine and view my files. So I have the following questions:
1) It appears that renaming the init file and restarting emacs does not keep the init file from interfering.
2) What do I have to do to disable using the init file?
3) What part of my init file could be causing this problem? Let me know if positing my entire init file would be helpful. Tramp related lines in my renamed init file .emacs.bkp are:
(add-to-list 'load-path "/usr/local/share/emacs/tramp/lisp/")
(require 'tramp)
(setq tramp-default-method "ssh")
(setq tramp-verbose 9)
Edit 2
I restored my init file using the original source I had backed up somewhere else. I used ediff-buffers to figure out the differences and restored all the differences to be the same as what I thought was in the corrupted init file. For some strange reason, the new init file looks exactly the same as my previous init file and tramp works fine now. In other words, I don't know what exactly got fixed but restoring my init file seemed to do the trick.

dbus error in emacs

I am trying to use notify.el on OS X, but every time get next error:
Symbol's value as variable is void: dbus-message-type-method-call
emacs --debug-init gives next output:
Debugger entered--Lisp error: (void-variable dbus-message-type-method-call)
dbus-call-method(:session "org.freedesktop.Notifications" "/org/freedesktop/DBus" "org.freedesktop.DBus.Peer" "Ping")
byte-code("\305^H!\203^S^#\306 \n^K\f\307\310^H&^G\202^Z^#\306 \n^K\f\307%?\207" [timeout bus service dbus-path-dbus dbus-interface-peer natnump dbus-call-method "Ping" :timeout] 8)
dbus-ping(:session "org.freedesktop.Notifications")
(and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications"))
(cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications")) (defvar notify-id 0 "Current D-Bus notification$
(setq notify-method (cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications")) (defvar notify-id 0 "Curren$
(cond ((null notify-method) (setq notify-method (cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications"))$
eval-buffer(#<buffer *load*-569235> nil "/Users/araeris/.emacs.d/packages/notify/notify.el" nil t) ; Reading at buffer position 3614
load-with-code-conversion("/Users/araeris/.emacs.d/packages/notify/notify.el" "/Users/araeris/.emacs.d/packages/notify/notify.el" nil t)
require(notify)
(if (fboundp name) nil (add-to-list (quote load-path) (concat (file-name-directory (or load-file-name (buffer-file-name))) "packages/" (symbol-name name))) (require name))
(progn (if (fboundp name) nil (add-to-list (quote load-path) (concat (file-name-directory (or load-file-name (buffer-file-name))) "packages/" (symbol-name name))) (require name)))
(while (consp --cl-var--) (setq name (car --cl-var--)) (progn (if (fboundp name) nil (add-to-list (quote load-path) (concat (file-name-directory (or load-file-name (buffer-file-name))) "packages/" (sym$
(let* ((--cl-var-- packages) (name nil)) (while (consp --cl-var--) (setq name (car --cl-var--)) (progn (if (fboundp name) nil (add-to-list (quote load-path) (concat (file-name-directory (or load-file-n$
(progn (let* ((--cl-var-- packages) (name nil)) (while (consp --cl-var--) (setq name (car --cl-var--)) (progn (if (fboundp name) nil (add-to-list (quote load-path) (concat (file-name-directory ...) "pa$
eval-buffer(#<buffer *load*> nil "/Users/araeris/.emacs.d/init.el" nil t) ; Reading at buffer position 1796
load-with-code-conversion("/Users/araeris/.emacs.d/init.el" "/Users/araeris/.emacs.d/init.el" t t)
load("/Users/araeris/.emacs.d/init" t t)
#[0 "^H\205\262^# \306=\203^Q^#\307^H\310Q\202;^# \311=\204^^^#\307^H\312Q\202;^#\313\307\314\315#\203*^#\316\202;^#\313\307\314\317#\203:^#\320\nB^R\321\202;^#\316\322^S\323^A\322\211#\210^K\322=\$
command-line()
normal-top-level()
Does anyone knows how to handle it?
P. S. I already installed dbus via homebrew.
You'll need to build Emacs with DBus support to actually use DBus. On OS X, that's rather unusual, and I can't see what you'd want to use DBus support in Emacs for, given that nothing else uses DBus on OS X.
If you're just after notifications, though, you don't need DBus. In fact, DBus won't give you notifications on OS X.
For notifications on OS X with notify.el, you need Growl. Namely, you must purchase Growl in the AppStore, or build it yourself, and additionally install Growlnotifier from http://growl.info/downloads.

Save buffer as a *.pdf with `ns-write-file-using-panel` or similar option

The existing code written by Rupert Swarbrick, later modified by Rory Yorke, still leaves open the need to specify the file location with a save-as function (e.g. on OSX, this would be ns-write-file-using-panel). Does anyone have a suggestion, please, that adds an option similar to ns-write-file-using-panel and/or perhaps modifies the /tmp directory option written in the script?
Word wrap for Emacs print buffer to PDF
Formatting a header in an Emacs function to print a buffer to PDF w/ line wrapping
(defun harden-newlines ()
(interactive)
"Make all the newlines in the buffer hard."
(save-excursion
(goto-char (point-min))
(while (search-forward "\n" nil t)
(backward-char)
(put-text-property (point) (1+ (point)) 'hard t)
(forward-char))))
;; (defun spool-buffer-given-name (name)
;; (load "ps-print")
;; (let ((tmp ps-left-header))
;; (unwind-protect
;; (progn
;; (setq ps-left-header
;; (list (lambda () name) 'ps-header-dirpart))
;; (ps-spool-buffer-with-faces))
;; (setf ps-left-header tmp))))
(defun spool-buffer-given-name (name)
(let ((ps-left-header (list (format "(%s)" name))))
(ps-spool-buffer-with-faces)))
(defun print-to-pdf ()
"Print the current file to /tmp/print.pdf"
(interactive)
(let ((wbuf (generate-new-buffer "*Wrapped*"))
(sbuf (current-buffer)))
(jit-lock-fontify-now)
(save-current-buffer
(set-buffer wbuf)
(insert-buffer sbuf)
;; (longlines-mode t)
(visual-line-mode t)
(harden-newlines)
(spool-buffer-given-name (buffer-name sbuf))
(kill-buffer wbuf)
(switch-to-buffer "*PostScript*")
(write-file "/tmp/print.ps")
(kill-buffer (current-buffer)))
(call-process "ps2pdf14" nil nil nil
"/tmp/print.ps" "/tmp/print.pdf")
(delete-file "/tmp/print.ps")
(message "PDF saved to /tmp/print.pdf")))
You can modify the last function to take a filename as a parameter:
(defun print-to-pdf (pdf-file-name)
"Print the current file to the given file."
(interactive "FWrite PDF file: ")
(let ((ps-file-name (concat (file-name-sans-extension pdf-file-name) ".ps"))
(wbuf (generate-new-buffer "*Wrapped*"))
(sbuf (current-buffer)))
(jit-lock-fontify-now)
(save-current-buffer
(set-buffer wbuf)
(insert-buffer sbuf)
(setq fill-column 95)
(longlines-mode t)
(harden-newlines)
(message (buffer-name sbuf))
(spool-buffer-given-name (buffer-name sbuf))
(kill-buffer wbuf)
(switch-to-buffer "*PostScript*")
(write-file ps-file-name t)
(kill-buffer (current-buffer)))
(call-process "ps2pdf14" nil nil nil ps-file-name pdf-file-name)
(delete-file ps-file-name)
(message "PDF saved to %s" pdf-file-name)))
You might want to add some code that tests if the PDF file already exist though, to avoid overwriting anything.

In-Place Word/Symbol Dabbrev Expand

Here's my extension to dabbrev-expand to support sub-string expansion.It works as expected, as far as I know. However I would find it even more useful if it supported in-symbol expansion similar to the behaviour of mdabbrev, which, by the way, is incomplete in terms of symbol-character and case-adjustment support. The pattern argument to dabbrev-substring-search, however, is only the pattern before point but for in-place expansions we need the pattern after point aswell. Why isn't this pattern available in hippie/dabbrev-expand and is there a preferred way to query it?
(defun dabbrev-substring-search (pattern &optional reverse limit syntax-context)
"Expand dabbrev substring. See:
http://www.emacswiki.org/cgi-bin/wiki/HippieExpand#toc5"
(let ((result ())
(regpat (cond ((not hippie-epxand-dabbrev-as-symbol)
(concat (regexp-quote pattern) W*))
;; ((eq (char-syntax (aref pattern 0)) ?_)
;; (concat (regexp-quote pattern)
;; "\\(\\sw\\|\\s_\\)*"))
(t
(concat "\\(?:"
Y<
"\\(" "\\(?:\\sw\\|\\s_\\)+" "\\)"
"\\(" (regexp-quote pattern) "\\)"
"\\(" "\\(?:\\sw\\|\\s_\\)*" "\\)"
Y>
"\\)"
"\\|"
"\\(?:"
Y<
"\\(" "\\(?:\\sw\\|\\s_\\)*" "\\)"
"\\(" (regexp-quote pattern) "\\)"
"\\(" "\\(?:\\sw\\|\\s_\\)+" "\\)"
Y>
"\\)"
)))))
(while (and (not result)
(if reverse
(re-search-backward regpat limit t)
(re-search-forward regpat limit t)))
(setq result (buffer-substring-no-properties (save-excursion
(goto-char (match-beginning 0))
;;(skip-syntax-backward "w_")
(point))
(match-end 0)))
(if (he-string-member result he-tried-table t)
(setq result nil))) ; ignore if bad prefix or already in table
(when nil
(when result
(let* ((p (point))
(end3 (match-end 3))
(beg2 (match-end 2))
(end2 (match-end 2))
(dummy (message "%s %s %s" end3 beg2 end2))
(beg (- end3 beg2)) ;begin offset from point
(end (- end3 end2))) ;end offset from point
(setq dabbrev-substring-match-region (cons beg end))
(hictx-generic (- p beg) (- p end) nil 'match 3))))
result))
;; Use: (dabbrev-substring-search "he")
(defun try-expand-dabbrev-substring-visible (old)
"Like `try-expand-dabbrev' but for visible part of buffer."
(interactive "P")
(let ((old-fun (symbol-function 'he-dabbrev-search)))
(fset 'he-dabbrev-search (symbol-function 'dabbrev-substring-search))
(unwind-protect (try-expand-dabbrev-visible old)
(fset 'he-dabbrev-search old-fun))))
(defun try-expand-dabbrev-substring (old)
"Like `try-expand-dabbrev' but for substring match."
(interactive "P")
(let ((old-fun (symbol-function 'he-dabbrev-search)))
(fset 'he-dabbrev-search (symbol-function 'dabbrev-substring-search))
(unwind-protect (try-expand-dabbrev old)
(fset 'he-dabbrev-search old-fun))))
(defun try-expand-dabbrev-substring-all-buffers (old)
"Like `try-expand-dabbrev-all-buffers' but for substring match."
(interactive "P")
(let ((old-fun (symbol-function 'he-dabbrev-search)))
(fset 'he-dabbrev-search (symbol-function 'dabbrev-substring-search))
(unwind-protect (try-expand-dabbrev-all-buffers old)
(fset 'he-dabbrev-search old-fun))))
which is activated for example using
(setq hippie-expand-try-functions-list
(append
'(
try-expand-dabbrev-substring-visible
try-expand-dabbrev-substring
try-expand-dabbrev-substring-all-buffers)))
This might or might not help. Like ordinary dabbrev, it works with the text before point, but candidate matching can be substring, regexp, or fuzzy (various kinds), in addition to prefix. Icicles - Dynamic Abbreviation