🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #2219

Re: Allowing SPACE in filename (find-file, dired, etc)

#2219
From: Young-il Choo
Date: Wed, 27 Jan 1993 22:27
84 lines
3745 bytes
In article <SHENTON.93Jan26134727@troll.gsfc.nasa.gov> shenton@troll.gsfc.nasa.gov (Chris Shenton) writes:

> I'm editing files which frequently have space in their filename, and
> would like the find-file functions in -- for example -- dired to
> recognize the fullname, not just up to the first space.

> Anyone have ideas on how to do this?

Here are some functions in "dired-plus.el", which are automatically loaded
by having the following in my .emacs

(setq dired-mode-hook
      (function
       (lambda ()
	 (require 'dired-plus))))


;;; dired-plus.el  -- modifications to handle file names containing spaces
;;; Dec 1992          Young-il Choo  <choo-young-il@cs.yale.edu>

;;The way I get the whole file name is by searching for eol.  This can cause
;;trouble since I like to have the symbolic links visible in dired-mode.  So,
;;I have a function that removes the stuff after " -> ".

(provide 'dired-plus)

(defun dired-get-long-filename (&optional localp no-error-if-not-filep)
  "In dired, return name of file, which may contain spaces,
mentioned on this line.
Value returned normally includes the directory name.
A non-nil 1st argument means do not include it.  A non-nil 2nd argument
says return nil if no filename on this line, otherwise an error occurs."
  (let (eol)
    (save-excursion
      (end-of-line)
      (setq eol (point))
      (beginning-of-line)
      (if (re-search-forward
	   "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
	   eol t)
	  (progn (skip-chars-forward " ")
		 (skip-chars-forward "^ " eol)
		 (skip-chars-forward " " eol)
		 (let ((beg (point)))
		   (skip-chars-forward "^\n") ;; first eol [YIC]
		   (dired-remove-symbolic-link ;; [YIC]
		    (if localp
			(buffer-substring beg (point))
		      ;; >> uses default-directory, could lose on cd, multiple.
		      (concat default-directory (buffer-substring beg (point))))
		    )
		   ))
	(if no-error-if-not-filep nil
	  (error "No file on this line"))))))

(defun dired-remove-symbolic-link (string)
  "Gets rid of the -> symbol in the string for dired."
  (substring string 0 
	     (if (string-match " -> " string) (match-beginning 0) nil)))

;;;(fset 'dired-simple-get-filename (symbol-function 'dired-get-filename))

(defun dired-get-filename (&optional localp no-error-if-not-filep)
  "Call \\[dired-get-long-filename].
Then, if dired-listing-switches contains the F flag,
fix up the filename by getting rid of the extra character."
  (let ((filename (dired-get-long-filename localp no-error-if-not-filep))
	eol)
    (if (and (string-match "F" dired-listing-switches)
	     (save-excursion
	       (end-of-line)
	       (setq eol (point))
	       (beginning-of-line)
	       (re-search-forward
		(concat "^."
			(if (string-match "i" dired-listing-switches)
			    "\\s-+[0-9]+" "")
			(if (string-match "s" dired-listing-switches)
			    "\\s-+[0-9]+" "")
			"\\s-+\\([ds]\\|\\-..x\\|\\-.....x\\|\\-........x\\)")
		eol t)))
	(substring filename 0 (1- (length filename)))
      filename)))
;;; end of dired-plus.el
Technical Details
Message-ID: <1993Jan27.222737.25636@cs.yale.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!canrem!telly!utzoo!torn!spool.mu.edu!yale.edu!cs.yale.edu!cs.yale.edu!choo
References: <SHENTON.93Jan26134727@troll.gsfc.nasa.gov>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.help
Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!canrem!telly!utzoo!torn!spool.mu.edu!yale.edu!cs.yale.edu!cs.yale.edu!choo
From: choo@cs.yale.edu (Young-il Choo)
Subject: Re: Allowing SPACE in filename (find-file, dired, etc)
In-Reply-To: shenton@troll.gsfc.nasa.gov's message of Tue, 26 Jan 1993 18: 47:27 GMT
Message-ID: <1993Jan27.222737.25636@cs.yale.edu>
Sender: news@cs.yale.edu (Usenet News)
Nntp-Posting-Host: systemsz-gw.cs.yale.edu
Organization: Yale Univ Computics
References: <SHENTON.93Jan26134727@troll.gsfc.nasa.gov>
Date: Wed, 27 Jan 1993 22:27:37 GMT
Lines: 84