From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#22300: 25.1.50; Dired -- renaming folders/files to CamelCase/UPPERCASE/lowercase. Date: Mon, 04 Jan 2016 11:45:22 -0800 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by - "") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1451936788 30029 80.91.229.3 (4 Jan 2016 19:46:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 4 Jan 2016 19:46:28 +0000 (UTC) Cc: 22300@debbugs.gnu.org, John Wiegley To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 04 20:46:16 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aGB55-0002rB-G0 for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 Jan 2016 20:46:15 +0100 Original-Received: from localhost ([::1]:46870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGB54-0004QA-Sz for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 Jan 2016 14:46:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGB4x-0004Ih-Q0 for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2016 14:46:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGB4s-0001Cg-Mh for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2016 14:46:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGB4s-0001CY-IR for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2016 14:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aGB4s-0003B5-DR for bug-gnu-emacs@gnu.org; Mon, 04 Jan 2016 14:46:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Jan 2016 19:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22300 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22300-submit@debbugs.gnu.org id=B22300.145193673012168 (code B ref 22300); Mon, 04 Jan 2016 19:46:02 +0000 Original-Received: (at 22300) by debbugs.gnu.org; 4 Jan 2016 19:45:30 +0000 Original-Received: from localhost ([127.0.0.1]:37893 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGB4M-0003AC-JD for submit@debbugs.gnu.org; Mon, 04 Jan 2016 14:45:30 -0500 Original-Received: from cobb.liquidweb.com ([50.28.13.150]:56585) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGB4L-0003A0-50 for 22300@debbugs.gnu.org; Mon, 04 Jan 2016 14:45:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com; s=default; h=Content-Type:MIME-Version:Subject:Cc:To:From:Message-ID:Date; bh=PW+txj3XODmY4zrB/u/HBCZ6fThapznO1936m+uFFb4=; b=5hDoGAKz3s1CtILUFerWKYSzWqlOhzO1Z0aTh3vzhaDl7JSMHfYiMZ9iEtcHSTd3CKuR6+XqVfi+ilI0vFbJvrQ2NJGDtPID5hU/m8+Y8CvF+KmEZNRoB0BswKZvHv/B; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:50373 helo=server.local.localhost) by cobb.liquidweb.com with esmtp (Exim 4.82) (envelope-from ) id 1aGB4C-0003n7-QZ; Mon, 04 Jan 2016 14:45:21 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cobb.liquidweb.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-Get-Message-Sender-Via: cobb.liquidweb.com: acl_c_relayhosts_text_entry: lawlist|lawlist.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111211 Archived-At: Thank you, John, for helping me answer Eli's question about situations when OSX uses case-insensitive versus case-sensitive. I didn't have the knowledge to be able to respond properly. Here is an unsophisticated workaround that bypasses `dired-create-files' when dealing with renaming when (1) 'darwin; (2) just one file; and, (3) the file names of to/from are equal if both are lower-cased. It doesn't do the fancy cutting/pasting of the new line in dired-mode and instead just reverts the entire buffer. (require 'dired-aux) (require 'cl) ;; for `lexical-let*' (defun dired-do-create-files (op-symbol file-creator operation arg &optional marker-char op1 how-to) "Create a new file for each marked file. Prompt user for a target directory in which to create the new files. The target may also be a non-directory file, if only one file is marked. The initial suggestion for target is the Dired buffer's current directory (or, if `dired-dwim-target' is non-nil, the current directory of a neighboring Dired window). OP-SYMBOL is the symbol for the operation. Function `dired-mark-pop-up' will determine whether pop-ups are appropriate for this OP-SYMBOL. FILE-CREATOR and OPERATION as in `dired-create-files'. ARG as in `dired-get-marked-files'. Optional arg MARKER-CHAR as in `dired-create-files'. Optional arg OP1 is an alternate form for OPERATION if there is only one file. Optional arg HOW-TO determines how to treat the target. If HOW-TO is nil, use `file-directory-p' to determine if the target is a directory. If so, the marked file(s) are created inside that directory. Otherwise, the target is a plain file; an error is raised unless there is exactly one marked file. If HOW-TO is t, target is always treated as a plain file. Otherwise, HOW-TO should be a function of one argument, TARGET. If its return value is nil, TARGET is regarded as a plain file. If it return value is a list, TARGET is a generalized directory (e.g. some sort of archive). The first element of this list must be a function with at least four arguments: operation - as OPERATION above. rfn-list - list of the relative names for the marked files. fn-list - list of the absolute names for the marked files. target - the name of the target itself. The rest of into-dir are optional arguments. For any other return value, TARGET is treated as a directory." (or op1 (setq op1 operation)) (let* ((fn-list (dired-get-marked-files nil arg)) (rfn-list (mapcar (function dired-make-relative) fn-list)) (dired-one-file ; fluid variable inside dired-create-files (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) (target-dir (dired-dwim-target-directory)) (default (and dired-one-file (expand-file-name (file-name-nondirectory (car fn-list)) target-dir))) (defaults (dired-dwim-target-defaults fn-list target-dir)) (target (expand-file-name ; fluid variable inside dired-create-files (minibuffer-with-setup-hook (lambda () (set (make-local-variable 'minibuffer-default-add-function) nil) (setq minibuffer-default defaults)) (dired-mark-read-file-name (concat (if dired-one-file op1 operation) " %s to: ") target-dir op-symbol arg rfn-list default)))) (into-dir (cond ((null how-to) ;; Allow DOS/Windows users to change the letter ;; case of a directory. If we don't test these ;; conditions up front, file-directory-p below ;; will return t because the filesystem is ;; case-insensitive, and Emacs will try to move ;; foo -> foo/foo, which fails. (if (and (memq system-type '(ms-dos windows-nt cygwin)) (eq op-symbol 'move) dired-one-file (string= (downcase (expand-file-name (car fn-list))) (downcase (expand-file-name target))) (not (string= (file-name-nondirectory (car fn-list)) (file-name-nondirectory target)))) nil (file-directory-p target))) ((eq how-to t) nil) (t (funcall how-to target))))) (if (and (consp into-dir) (functionp (car into-dir))) (apply (car into-dir) operation rfn-list fn-list target (cdr into-dir)) (if (not (or dired-one-file into-dir)) (error "Marked %s: target must be a directory: %s" operation target)) ;; rename-file bombs when moving directories unless we do this: (or into-dir (setq target (directory-file-name target))) ;;; BEGIN modification by @lawlist (if (and (eq system-type 'darwin) dired-one-file (equal op1 "Rename") (equal operation "Move") (equal (downcase (expand-file-name dired-one-file)) (downcase (expand-file-name target)))) ;; Penetrate the `set-process-sentinel' with `lexical-let'. (lexical-let* ((dired-one-file dired-one-file) (target target)) (set-process-sentinel (start-process "rename" nil "mv" dired-one-file target) (lambda (p e) (when (= 0 (process-exit-status p)) (revert-buffer) (message "Renamed %s to %s" dired-one-file target))))) (dired-create-files file-creator operation fn-list (if into-dir ; target is a directory ;; This function uses fluid variable target when called ;; inside dired-create-files: (function (lambda (from) (expand-file-name (file-name-nondirectory from) target))) (function (lambda (_from) target))) marker-char)) ;;; END modification by @lawlist )))