Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make up-item smart #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion direx.el
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
(defmethod direx:node-children (node)
nil)

(defgeneric direx:node-parent (node)
"Returns the parent of the NODE.")

(defmethod direx:node-parent (node)
nil)

(defgeneric direx:node-contains (node descendant)
"Returns t if the NODE has the DESCENDANT. The default
implementation of this generic function uses
Expand Down Expand Up @@ -189,6 +195,9 @@ descendants. You may add a heuristic method for speed.")
(loop for child-tree in (direx:node-children (direx:item-tree item))
collect (direx:make-item child-tree item)))

(defun direx:make-item-parent (item)
(direx:node-parent (direx:item-tree item)))

(defun direx:item-equals (x y)
(direx:tree-equals (direx:item-tree x) (direx:item-tree y)))

Expand Down Expand Up @@ -404,6 +413,11 @@ mouse-2: find this node in other window"))
(and (typep y 'direx:file)
(equal (direx:file-full-name x) (direx:file-full-name y)))))

(defmethod direx:node-parent ((file direx:file))
(let ((parent (file-name-directory (directory-file-name (direx:file-full-name file)))))
(when (and parent (file-directory-p parent))
(direx:make-directory parent))))

(defclass direx:regular-file (direx:file direx:leaf)
())

Expand Down Expand Up @@ -711,7 +725,14 @@ mouse-2: find this node in other window"))
(defun direx:up-item ()
(interactive)
(direx:aif (direx:item-at-point)
(direx:up-item-1 it)
(when (eq (point)
(progn (direx:up-item-1 it) (point)))
(direx:aif (direx:make-item-parent it)
(let ((buffer-read-only nil))
(erase-buffer)
(direx:add-root-into-buffer it (current-buffer))
(rename-buffer (direx:tree-name it) t))
(error "No parent")))
(goto-char (point-min))))

(defun direx:down-item ()
Expand Down