help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

elisp: interactive and non-interactive diffs


From: rustom
Subject: elisp: interactive and non-interactive diffs
Date: Wed, 08 Dec 2010 15:35:32 -0000
User-agent: G2/1.0

There is this graphviz mode
http://www.google.com/url?sa=D&q=http://users.skynet.be/ppareit/projects/graphviz-dot-mode/graphviz-dot-mode.html&usg=AFQjCNEcMFB8SEMF-UJ09pEbTvqGIAzcow

I was trying to make it more electric so that the graph can keep on
previewing as it changes:
For that I tried

(defun compile-and-preview ()
  (interactive)
  (compile compile-command)
  (graphviz-dot-preview)
)

compile-command is locally bound to something like
"dot -Tpng /path/to/something.dot > /path/to/something.png"

However while the compile followed by graphviz-dot-preview work
compile-and-preview doesn't.

I guess the offending code is here (though not sure)
Note particularly the "...this is ugly..." section

Can someone make out the intention of this code?


(defun graphviz-dot-preview ()
  "Shows an example of the current dot file in an emacs buffer.
This assumes that we are running GNU Emacs or XEmacs under a windowing
system.
See `image-file-name-extensions' for customizing the files that can be
loaded in GNU Emacs, and `image-formats-alist' for XEmacs."
  (interactive)
  ;; unsafe to compile ourself, ask it to the user
  (if (buffer-modified-p)
      (message "Buffer needs to be compiled.")
    (if (string-match "XEmacs" emacs-version)
        ;; things are easier in XEmacs...
        (find-file-other-window (concat (file-name-sans-extension
                                         buffer-file-name)
                                        "." graphviz-dot-preview-extension))
      ;; run through all the extensions for images
      (let ((l image-file-name-extensions))
        (while
            (let ((f (concat (file-name-sans-extension (buffer-file-
name))
                             "."
                             (car l))))
              ;; see if a file matches, might be best also to check
              ;; if file is up to date TODO:PP
              (if (file-exists-p f)
                  (progn (auto-image-file-mode 1)
                         ;; OK, this is ugly, I would need to
                         ;; know how I can reload a file in an
existing buffer
                         (if (get-buffer "*preview*")
                             (kill-buffer "*preview*"))
                         (set-buffer (find-file-noselect f))
                         (rename-buffer "*preview*")
                         (display-buffer (get-buffer "*preview*"))
;                        (switch-to-buffer-other-frame (get-buffer "*preview*"))
                         ;; stop iterating
                         '())
                ;; will stop iterating when l is nil
                (setq l (cdr l)))))
      ;; each extension tested and nothing found, let user know
      (when (eq l '())
        (message "No image found."))))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]