GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


d-find.el

    

;;; d-find.el

;; Copyright (C) 2014-2015 Davin Pearson

;; Emacs Lisp Archive Entry
;; Filename: d-find.el
; Author/Maintainer: Davin Max Pearson <http://davin.50webs.com>
;; Keywords: find functionality
;; Version: 1.0

;;; Commentary:

;; This file is not part of GNU Emacs.

;;; Limitation of Warranty

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more detail.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs, see the file COPYING.  If not, see:
;;
;; <http://www.gnu.org/licenses/gpl-3.0.txt>.


;;; Install Instructions:
;; See the following URL for the latest info and a tarball:
;;
;; <http://davin.50webs.com/research/2010/mopa2e2.html#d-find>
;;
;; Then untar the tarball to a folder pointed to by the Emacs variable
;; load-path and add the following line to your ~/.emacs file.
;;
;; (require 'd-find)

;;; Known Bugs:

;; None so far!

;;; Code:

(when prefs-davins-keybindings-online-p
  (global-set-key "\C-f" 'd-find-file)
  (global-set-key "\C-d" 'd-find-file)
  (global-set-key "\C-xf" 'd-find-file)
  (global-set-key "\C-xd" 'dired)
  (global-set-key "\C-x\C-f" 'd-find-file)
  (global-set-key "\C-x\C-d" 'dired)
  )

(defun d-find--keybindings ()
  (progn
    (define-key dired-mode-map [(enter)] 'd-dired-advertised-find-file)
    (define-key dired-mode-map "\C-m"    'd-dired-advertised-find-file)
    )
  )
;; end defun: d-find--keybindings ()

(add-hook 'dired-mode-hook 'd-find--keybindings)

;; (setq filename "~/davins-stuff.lnk")
(defun d-find-file (filename)
  "Edit file FILENAME.  Wildcards are accepted."
  (interactive "FMy Find File/Folder: ")
  ;;(debug "Duck")
  (assert filename)
  ;;(debug "Madonna / Ray Of Light, filename=%s" filename)
  ;;(d-beeps "filename=%s" filename)
  (setq buffer-save-without-query t)
  (if (fboundp 'd-recent-find-file-hook)
      (d-recent-find-file-hook filename))

(if (file-directory-p filename)
      (and 1 (dired filename))
    (if (string-match "\\.lnk$" filename)
        (let (shortcut)
          (save-window-excursion
            (setq buf (find-file filename))
            (goto-char (point-min))
            (if (re-search-forward "\0\\([a-zA-Z]:\\\\\\(\\\\\\|[-a-zA-Z0-9' _]\\)*\\)\0" nil t)
                (progn
                  (setq shortcut (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
                  (kill-buffer buf))
              (kill-buffer buf)
              (error "Error in shortcut file %s" filename)
              ))
          (when shortcut
            (message "Following link %s -> %s" filename shortcut)
            (find-file shortcut))) ;; END LET SHORTCUT!
      (if (string-match "\\*" filename)
          (progn
            ;;(d-foo)
            (find-file filename 'WILDCARDS))
        (let ((case-fold-search t))
          (cond
           ;; ----------------------------------------------------------
           ((and (buffer-file-name)
                 (string= (expand-file-name filename) (expand-file-name (buffer-file-name))))
            ;;(d-beeps "foo!")
            (and 2 (dired (file-name-directory filename)))
            )
           ;; ----------------------------------------------------------
           ((file-directory-p filename)
            ;;(d-beeps "123")
            (if (string-match "/\\(Driver Pack Solution\\)/" filename)
                (progn
                  (setq filename (substring filename (match-end 1) (1- (length filename))))
                  (if (string= "" filename)
                      (and 3 (dired (concat drive-f ":/Driver Pack Solution/")))
                    (if (get-buffer "Driver Pack Solution")
                        (progn
                          (switch-to-buffer "Driver Pack Solution")
                          (goto-char (point-min))
                          (re-search-forward filename nil t)
                          (beginning-of-line)
                          ;;(d-dired-advertised-find-file)
                          ;;(dired-next-line 2)
                          ;;(d-beeps "f=%s" filename)
                          )
                      (and 4 (dired filename)))))
              (and 5 (dired filename))
              ))
           ;; ----------------------------------------------------------
           ((or os-type-mswindows-p os-type-msdos-p)
            ;;(d-beeps "Regina")
            (cond

((string-match "\\.exe$" filename)
              (shell-command (concat "\"" filename "\"")))

((string-match "\\.pdf$" filename)
              (shell-command (concat "\"c:/Program Files (x86)/Adobe/Reader 11.0/Reader/AcroRd32.exe\" " filename))
              )

((string-match "\\.flac$" filename)
              (save-window-excursion
                (shell-command (concat "\"c:/Program Files/foobar2000/foobar2000.exe\" \"" filename "\" &"))))

((string-match "\\.\\(ico\\|bmp\\|jpe?g\\|mpe?g\\|png\\|gif\\)$" filename)
              (save-window-excursion
                (if (file-exists-p "c:/Program Files/IrfanView/i_view32.exe")
                    (shell-command (concat "\"c:/Program Files/IrfanView/i_view32.exe\" \"" filename "\" &"))
                  (if (file-exists-p "c:/Program Files (x86)/IrfanView/i_view32.exe")
                      (shell-command (concat "\"c:/Program Files (x86)/IrfanView/i_view32.exe\" \"" (file-name-nondirectory filename) "\" &"))
                    (d-beeps "Cannot find IrfanView")
                    ))))
             ((string-match "\\.\\(exe\\)$" filename)
              ;;(save-window-excursion
              (shell-command (concat filename " &"))
              )

((string-match "\\.mid$" filename)
              ;;(d-beeps "Foomatic")
              (shell-command (concat "\"c:/Program Files/Windows Media Player/mplayer2.exe\" \"" filename "\" &")))

((string-match "\\.level$" filename)
              (find-file filename)
              (setq truncate-lines t))

;;((string-match (concat "\\." d-files-regexp--archives "$") filename)
             ;;(shell-command (concat "cygstart \"" (expand-file-name filename) "\"")))

             ((or (string-match "\\.wav$" filename)
                  (string-match "\\.au$"  filename))
              ;;(debug "Carrot")
              (play-sound (list 'sound :file filename :volume 1.0)))

((string-match "\\.rle$" filename)
              (shell-command (concat "rle-loader.exe " filename)))

((string-match "\\.xcf$" filename)
              (shell-command (concat "\"~/../Program Files/GIMP-2.2/bin/gimp-2.2.exe\" " filename)))

((string-match "\\.exe$" filename)
              (shell-command (concat "cd " default-directory "; ./" filename)))

((string-match "\\.\\(pdf\\|eps\\)$" filename)
              (shell-command "\"/cygdrive/c/Program Files/Adobe/Reader 11.0/Reader/AcroRd32.exe\" " filename))

;;(shell-command "\"c:/Program Files/Adobe/Reader 11.0/AcroRd32.exe\" " filename))

             ((string-match "\\.ps$" filename)
              (shell-command (concat "\"d:/home/Program Files/gs/gs8.53/bin/gswin32.exe\" " filename)))

((string-match "\\.mp4$" filename)
              ;;(d-beeps "hello")
              (shell-command (concat "\"c:/Program Files/VideoLAN/VLC/vlc.exe\" \"" filename "\" &")))

;; NOTE: cygstart
             ((string-match (concat "\\.\\("
                                    "avi\\|bmp\\|eps\\|gif\\|iff\\|ico\\|jpg\\|jpeg\\|"
                                    "mpeg\\|mov\\|mpg\\|pcx\\|pdf\\|png\\|tga\\|wmv\\|" ;;; graphics files (missing dvi)
                                    "doc\\|rtf\\|" ;;; MS Word
                                    "exe\\|"       ;;; executable
                                    "swf\\|"       ;;; ShockWaveFlash
                                    "hlp\\|"       ;;; help
                                    "au\\|mid\\|mp3\\|wav\\|wma\\|" ;;; sound files
                                    "rtf\\|pdf\\|ps\\|" ;;; latex
                                    ;;"sex\\|"
                                    "\\)$") filename)
              ;;(let ((shell-file-name "D:/Program Files/emacs-21.3/bin/cmdproxy.exe"))
              (let ((cmd nil))
                (save-window-excursion
                  ;;(d-foo)
                  (setq cmd (concat "e:/cygwin/bin/cygstart.exe \"" (expand-file-name filename) "\""))
                  (message "cmd=%s" cmd)
                  (shell-command cmd)
                  )))

((string-match "\\.fig$" filename)
              (save-window-excursion
                ;;(shell-command (concat "c:/cygwin/usr/X11R6/bin/xfig.exe " (prin1-to-string filename) " &"))
                (shell-command (concat "c:/cygwin/bin/xfig.exe " (prin1-to-string filename) " &"))
                ))

(t (find-file (file-truename filename)))
             ))
           ;; ----------------------------------------------------------
           (os-type-linux-p
            ;;(debug "David Bowie / 1989 - Tin Machine filename=%s" filename)
            (cond
             ((or (string-match "\\.wav$" filename)
                  (string-match "\\.au$"  filename))
              (play-sound (list 'sound :file filename :volume 1.0))
              ;;(debug "ABBA / Mamma Mia")
              )

;;((string-match "\\.wav$" filename)
             ;; ;;(debug "Public Enemy / The Evil Empire of Everything / Say It Like It Really Is")
             ;; ;;(debug "Ed Sheeran / Divide / Supermarket Flowers")
             ;; (shell-command "emacs --batch --eval \"(setq file-to-play \"/media/www/C1TB/sound-samples/emacs/completed-build-book.wav\")\" --load /media/www/C1TB/home/dlisp/play-wav.el"))

             ((string-match "\\.\\(pdf\\|dvi\\|eps\\|ps\\)$" filename)
              (shell-command "evince " (prin1-to-string filename) " &"))

((string-match "\\.exe$" filename)
              (save-window-excursion
                (shell-command filename)))

((string-match "\\.fig$" filename)
              (save-window-excursion
                (shell-command (concat "xfig \"" filename "\" &"))))

((string-match "\\.\\(bmp\\|gif\\|jpg\\|jpeg\\|ico\\|mpe?g\\|pgm\\|png\\|tga\\)$" filename)
              (save-window-excursion
                ;;(shell-command (concat "xv -geometry 1024x768 " filename " &"))
                ;;(shell-command (concat "eog -f " filename " &"))
                ;;(d-beeps "gpicview")
                (shell-command (concat "gpicview \"" (expand-file-name filename) "\" &"))
                ))

((or (string-match "\\.wav$" filename)
                  (string-match "\\.au$"  filename)
                  ;;(string-match "\\.mid$" filename)
                  )
              ;;(debug "Carrot")
              (play-sound (list 'sound :file filename :volume 1.0)))

((or (string-match "\\.mid$" filename)
                  (string-match "\\.flac$" filename))
              ;;(d-beeps "audacious")
              (shell-command (concat "audacious \"" filename "\" &")))

((string-match "\\.\\(dvi\\|eps\\|ps\\)$" filename)
              (shell-command (concat "nautilus " filename " &")))

((string-match "\\.pdf$" filename)
              (save-window-excursion
                (shell-command (concat "acroread " (prin1-to-string filename) " &"))))

((string-match "\\.dvi$" filename)
              (save-window-excursion
                (shell-command (concat "xdvi " (prin1-to-string filename) " &"))))

(t (find-file (file-truename filename)))

))

(t (find-file (file-truename filename)))
           )))))
  (if (fboundp 'd-speedbar)
      (delete-other-windows))
  (setq file-name-history (cons "~/" file-name-history))
  )
;; end defun: d-find-file (filename)


(defun d-dired-advertised-find-file () (interactive) ;;(debug "Elvis Presley / That's All Right") (let ((filename (d-dired-get-current-file))) (assert filename) ;;(debug "Ella Fitzgerald / Sings Sweet Songs For Swingers / I Remember You") (push-mark) (when (string-match "^\\(.*\\) -> \\(.*\\)$" filename) (setq filename (substring filename (match-beginning 1) (match-end 1)))) (d-find-file filename) )) ;; end defun: d-dired-advertised-find-file () (defun d-dired-get-current-file () (save-excursion (assert (eq major-mode 'dired-mode)) (safe-command (dired-next-line 1) 'QUIETP) (safe-command (dired-previous-line 1) 'QUIETP) (let ((filename (d-buffer-substring (point) (save-excursion (re-search-forward "[\n\r]" nil t) (backward-char) (point)))) dirname fullname) ;;(debug "Hot tomales") (cond ((re-search-backward "^ \\([a-z]:/.*\\):$" nil t) (setq dirname (buffer-substring-no-properties (match-beginning 1) (match-end 1))) (setq fullname (concat dirname "/" filename)) ;;(debug "zoom 1") ) ((re-search-backward "^ \\(/[][(){}_a-zA-Z0-9/'.,+! #&;-]*\\):$" nil t) (setq dirname (buffer-substring-no-properties (match-beginning 1) (match-end 1))) ;;(d-beeps "dirname=%s" dirname) (setq fullname (concat dirname "/" filename)) ;;(debug "zoom 2") ) ;;(t (debug "Roger")) ) ;;(debug "zoom 3") fullname ))) ;; end defun: d-dired-get-current-file () (add-hook 'shell-mode-hook 'd-shell-mode-hook) (defun d-shell-mode-hook () (when prefs-davins-keybindings-online-p (local-set-key "\C-d" 'd-find-file)) ) (d-quote (string-match "\\.\\$" filename) (shell-command (concat "start \"" filename "\"")) (d-quote (if (get-buffer ".script.bat") (kill-buffer ".script.bat")) (save-excursion (set-buffer (find-file ".script.bat")) (read-only-mode -1) (erase-buffer) (insert "start " filename "\r\n") (save-buffer) (kill-buffer nil) (shell-command (concat "\"" default-directory ".script.bat\"")) (delete-file (concat default-directory ".script.bat")) ))) (defadvice save-buffer (around d-find activate) (push-mark (point) 'NOMSG) ad-do-it (if mark-ring (goto-char (car mark-ring)))) (defadvice save-some-buffers (around d-find activate) (push-mark (point) 'NOMSG) ad-do-it (if mark-ring (goto-char (car mark-ring)))) (provide 'd-find)
Back
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Mon May 6 01:57:07 NZST 2019
Best viewed at 800x600 or above resolution.
© Copyright 1999-2019 Davin Pearson.
Please report any broken links to