Changeset - 32f960186ab2
[Not reviewed]
0 2 1
Sergey Pashinin - 13 years ago 2013-05-07 02:07:29
sergey@pashinin.com
dired serialize in special buffers (could not restore remote dirs)
3 files changed with 35 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/workgroups-misc.el
Show inline comments
 
new file 100644
 
(defun wg-string/starts-with (s arg)
 
  "returns non-nil if string S starts with ARG.  Else nil."
 
  (cond ((>= (length s) (length arg))
 
         (string-equal (substring s 0 (length arg)) arg))
 
        (t nil)))
 

	
 
(defun wg-is-file-remote (filename)
 
  "Return t if filename starts with \"/ssh:\" or \"/sudo:\""
 
  (interactive)
 
  (or (wg-string/starts-with filename "/ssh:")
 
      (wg-string/starts-with filename "/sudo:")))
 

	
 
;; (wg-is-file-remote "/sudo:/etc/myfile")
 

	
 
(provide 'workgroups-misc)
src/workgroups-specialbufs.el
Show inline comments
 
;;; special buffer serdes functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;;
 
;; TODO: Possibly add restore-special-data customization option
 
;; TODO: These could be a little more thorough
 
;;
 

	
 
(require 'dflet)
 
(require 'workgroups-misc)
 

	
 
;; Dired
 

	
 
(defun wg-deserialize-dired-buffer (buf)
 
  "Deserialize Dired buffer."
 
  (wg-dbind (this-function params) (wg-buf-special-data buf)
 
    (let ((dir (car params)))
 
      (if (file-exists-p dir)
 
          (dired dir))
 
      (current-buffer))))
 

	
 
(defun wg-serialize-dired-buffer (buffer)
 
  "Serialize Dired buffer."
 
  (with-current-buffer buffer
 
    (when (eq major-mode 'dired-mode)
 
      (list 'wg-deserialize-dired-buffer
 
            (wg-take-until-unreadable (list (or (buffer-file-name) default-directory)))
 
            ))))
 

	
 
;; Info buffer serdes
 

	
 
(defun wg-deserialize-Info-buffer (buf)
 
  "Deserialize an Info buffer."
 
  (require 'info)
 
  (wg-aif (cdr (wg-buf-special-data buf))
 
      (apply #'Info-find-node it)
 
    (info))
 
  (current-buffer))
 

	
 
(defun wg-serialize-Info-buffer (buffer)
 
  "Serialize an Info buffer."
 
  (with-current-buffer buffer
 
    (when (eq major-mode 'Info-mode)
 
      (wg-when-boundp (Info-current-file Info-current-node)
 
        (list 'wg-deserialize-Info-buffer
 
              Info-current-file
 
              Info-current-node)))))
 

	
 

	
 
;; help buffer serdes
 

	
 
(defun wg-deserialize-help-buffer (buf)
src/workgroups-variables.el
Show inline comments
 
@@ -179,48 +179,49 @@ minibuffer is active."
 
    (vertical-scroll-bar nil nil))
 
  "Alist mapping buffer-local variable symbols to serdes functions.
 

	
 
The `car' of each entry should be a buffer-local variable symbol.
 

	
 
The `cadr' of the entry should be either nil or a function of no
 
arguments.  If nil, the variable's value is used as-is, and
 
should have a readable printed representation.  If a function,
 
`funcall'ing it should yield a serialization of the value of the
 
variable.
 

	
 
The `caddr' of the entry should be either nil or a function of
 
one argument.  If nil, the serialized value from above is
 
assigned to the variable as-is.  It a function, `funcall'ing it
 
on the serialized value from above should do whatever is
 
necessary to properly restore the original value of the variable.
 
For example, in the case of `major-mode' it should funcall the
 
value (a major-mode function symbol) rather than just assigning
 
it to `major-mode'."
 
  :type 'alist
 
  :group 'workgroups)
 

	
 
(defcustom wg-special-buffer-serdes-functions
 
  '(wg-serialize-Info-buffer
 
    wg-serialize-dired-buffer
 
    wg-serialize-org-agenda-buffer
 
    wg-serialize-help-buffer
 
    wg-serialize-ielm-buffer
 
    wg-serialize-shell-buffer
 
    wg-serialize-eshell-buffer
 
    wg-serialize-term-buffer
 
    wg-serialize-magit-buffer
 
    )
 
  "List of functions providing special buffer serialization/deserialization.
 
An entry should be either a function symbol or a lambda, and should
 
accept a single Emacs buffer object as an argument.
 

	
 
When a buffer is to be serialized, it is passed to each of these
 
functions in turn until one returns non-nil, or the list ends.  A
 
return value of nil indicates that the function can't handle
 
buffers of that type.  A non-nil return value indicates that it
 
can.  The first non-nil return value becomes the buffer's special
 
serialization data.  The return value should be a cons, with a
 
deserialization function (a function symbol or a lambda) as the car,
 
and any other serialization data as the cdr.
 

	
 
When it comes time to deserialize the buffer, the deserialization
 
function (the car of the cons mentioned above) is passed the
 
wg-buf object, from which it should restore the buffer.  The
0 comments (0 inline, 0 general)