From: Alin Soare <as1789@gmail.com>
To: emacs-devel@gnu.org
Subject: Midnight commander quick view.
Date: Thu, 11 Sep 2014 17:51:57 +0300 [thread overview]
Message-ID: <87sijy5hwy.fsf@gmail.com> (raw)
I sent a stub for quick-view like in mc a few weeks ago.
I sent here the latest version that I have been using for more than 10
days, and it seems stable. I did not need to modify it in the last past
10 days, even if I used it each day many times.
Switch qv on and off is done with C-c C-q . It is buffer local. If we
change the directory in dired, we have to reactivate it.
;;; -*- lexical-binding:t -*-
(require 'dired)
(defun qv ()
(let ((config (current-window-configuration))
(max-size 1e4)
(qv-buffer (get-buffer-create "*quick view*")))
(defvar exit-keybinding
(lambda (&optional arg)
(interactive)
(apply quick-view-object (list 'exit))))
(defvar init-keybinding
(lambda (&optional arg)
(interactive)
(setq-local quick-view-object (qv))
(apply quick-view-object '(init))
(message "enter quick view")))
(defun get-key () init-keybinding)
(defun update ()
(let ((f (dired-get-filename nil t)))
(defun file-not-readable-p ()
(and (stringp f)
(file-regular-p f)
(not (file-readable-p f))))
(defun regular-file-p ()
(and (stringp f)
(file-regular-p f)
(file-readable-p f)))
(defun already-opened-file-p ()
(and (stringp f)
(file-regular-p f)
(get-file-buffer f)))
(with-current-buffer qv-buffer
(setq buffer-read-only nil)
(cond ((already-opened-file-p)
(erase-buffer)
(insert-buffer-substring (get-file-buffer f)))
((regular-file-p)
(erase-buffer)
(insert-file-contents-literally
f nil 0 (min max-size (nth 7 (file-attributes f))))
(and (< max-size (nth 7 (file-attributes f)))
(message "header preview truncated at byte %d" max-size)))
((file-not-readable-p)
(erase-buffer)
(insert "-- file not readble --"))
(t (erase-buffer)
(insert "-- no file at point --")))
(set-buffer-modified-p nil)
(setq buffer-read-only t
buffer-file-name nil))))
(defun init ()
(delete-other-windows)
(split-window-sensibly)
(balance-windows)
(with-selected-window
(save-window-excursion (other-window 1)
(selected-window))
(switch-to-buffer qv-buffer)
(setq buffer-undo-list t))
(add-hook 'post-command-hook 'update 'at-the-end t)
(define-key dired-mode-map [(control ?c) (control ?q)]
exit-keybinding)
(setq undo-outer-limit max-size)
(dired-hide-details-mode +1))
(defun exit ()
(setq-local quick-view-object nil)
(remove-hook 'post-command-hook 'update t)
(define-key dired-mode-map [(control ?c) (control ?q)]
init-keybinding )
(kill-buffer qv-buffer)
(dired-hide-details-mode -1)
(set-window-configuration config)
(message "exit qv"))
(lambda (message) (apply message '()))))
(define-key dired-mode-map [(control ?c) (control ?q)]
(apply (qv) '(get-key)))
--
No GNUs is bad news.
next reply other threads:[~2014-09-11 14:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-11 14:51 Alin Soare [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-08-25 2:26 Midnight Commander Quick View Alin Soare
2014-08-25 14:38 ` Stefan Monnier
2014-08-25 19:30 ` Alin
2014-08-26 17:45 ` Stefan Monnier
2014-08-27 6:33 ` Alin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sijy5hwy.fsf@gmail.com \
--to=as1789@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.