[Top][All Lists]

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

Midnight Commander Quick View

From: Alin Soare
Subject: Midnight Commander Quick View
Date: Mon, 25 Aug 2014 05:26:28 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

I needed quick view option, like in midnight commander, and I wrote this

I want to ask if you know something that already exists and does a
similar job. My code is not complete -- for example, for large files, I
want to see only the header, not to load all the file.

In my emacs this code works as I expect to work. I did not test it
outside -- but it should work as well.


(setq lexical-binding t)
(require 'dired)

(defun qv-update ()
  (let ((f (dired-get-filename t t)))
    (when (and (stringp f) (file-regular-p f)
               (< (nth 7 (file-attributes f)) 1e7))
      (when (not (equal (window-buffer)
                          (window-buffer (other-window 1)))))
          (other-window 1)
          (and buffer-read-only
               (not (buffer-modified-p))
               (kill-buffer (window-buffer)))))
      (view-file-other-window f)
       (other-window 1))))

(defun qv ()
  (let ((i 0))
    (let ((config (current-window-configuration)))
      (add-hook 'post-command-hook 'qv-update)
      (lambda (message)
        (defun exit ()
          (setq-local quick-view-object nil)
          (define-key dired-mode-map
            [(control ?c) (control ?q)]
          (setq i (1- i))
          (set-window-configuration config)
          (remove-hook 'post-command-hook 'qv-update)
          (message "exit qv"))
        (apply message '())))))

(setq-local qv-binding
    (lambda (&optional arg)
      (setq-local quick-view-object (qv))
      (define-key dired-mode-map [(control ?c) (control ?q)]
        (lambda (&optional arg)
          (dired-next-line 1)
          (apply quick-view-object (list 'exit))))))

(define-key dired-mode-map
  [(control ?c) (control ?q)]

No GNUs is bad news.

reply via email to

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