unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer
@ 2011-09-15  8:39 Masatake YAMATO
  2011-09-15 13:03 ` Stefan Monnier
  2012-04-12 19:52 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 6+ messages in thread
From: Masatake YAMATO @ 2011-09-15  8:39 UTC (permalink / raw)
  To: 9511

This is a request for merge a patch to official GNU Emacs source tree.
Following patch adds a function to move the point to / with
C-M-f and C-M-b when reading a filename from minibuffer.
See also the thread at http://lists.gnu.org/archive/html/emacs-devel/2011-09/msg00155.html


2011-09-15  Masatake YAMATO  <yamato@redhat.com>

	* minibuffer.el (minibuffer-local-filename-syntax): New variable.
	(read-file-name-default): Install the syntax table.

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2011-09-02 00:36:58 +0000
+++ lisp/minibuffer.el	2011-09-15 06:27:34 +0000
@@ -1997,6 +1997,31 @@
   (funcall (or read-file-name-function #'read-file-name-default)
            prompt dir default-filename mustmatch initial predicate))
 
+(defvar minibuffer-local-filename-syntax
+  (let ((table (make-syntax-table))
+	(punctuation (car (string-to-syntax "."))))
+    ;; Convert all punctuation entries to symbol.
+    (map-char-table (lambda (cc syntax)
+		      (when (and syntax
+				 (eq (car syntax)
+				     punctuation))
+			(let* ((cons? (consp cc))
+			       (begin (if cons? (car cc) cc))
+			       (end (if cons? (cdr cc) begin))
+			       (c begin))
+			  (while (<= c end)
+			    (modify-syntax-entry c "_" table)
+			    (setq c (1+ c))))))
+		    table)
+    (mapc
+     (lambda (c)
+       (modify-syntax-entry c "." table))
+     '(?/
+       ?: ?\\
+       ))
+    table)
+  "Syntax table to be used in minibuffer for reading file name.")
+
 ;; minibuffer-completing-file-name is a variable used internally in minibuf.c
 ;; to determine whether to use minibuffer-local-filename-completion-map or
 ;; minibuffer-local-completion-map.  It shouldn't be exported to Elisp.
@@ -2065,7 +2090,9 @@
                                (lambda ()
                                  (with-current-buffer
                                      (window-buffer (minibuffer-selected-window))
-				   (read-file-name--defaults dir initial)))))
+				   (read-file-name--defaults dir initial))))
+			  (set-syntax-table minibuffer-local-filename-syntax)
+			  )
                       (completing-read prompt 'read-file-name-internal
                                        pred mustmatch insdef
                                        'file-name-history default-filename)))






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer
  2011-09-15  8:39 bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer Masatake YAMATO
@ 2011-09-15 13:03 ` Stefan Monnier
  2011-09-15 14:05   ` Masatake YAMATO
  2012-04-12 19:52 ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2011-09-15 13:03 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: 9511

> +		      (when (and syntax
> +				 (eq (car syntax)
> +				     punctuation))

If syntax is nil, (car syntax) is nil, so the above is equivalent to

	      (when (eq (car syntax) punctuation)

> +			(let* ((cons? (consp cc))
> +			       (begin (if cons? (car cc) cc))
> +			       (end (if cons? (cdr cc) begin))
> +			       (c begin))
> +			  (while (<= c end)
> +			    (modify-syntax-entry c "_" table)
> +			    (setq c (1+ c))))))

Aka (modify-syntax-entry cc "_" table), since it accepts the same "cons
to represent a range" convention ;-)


        Stefan





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer
  2011-09-15 13:03 ` Stefan Monnier
@ 2011-09-15 14:05   ` Masatake YAMATO
  0 siblings, 0 replies; 6+ messages in thread
From: Masatake YAMATO @ 2011-09-15 14:05 UTC (permalink / raw)
  To: monnier; +Cc: 9511

Thank you for reviwing again.

=== modified file 'lisp/minibuffer.el'
*** lisp/minibuffer.el	2011-09-02 00:36:58 +0000
--- lisp/minibuffer.el	2011-09-15 13:48:51 +0000
***************
*** 1997,2002 ****
--- 1997,2020 ----
    (funcall (or read-file-name-function #'read-file-name-default)
             prompt dir default-filename mustmatch initial predicate))
  
+ (defvar minibuffer-local-filename-syntax 
+   (let ((table (make-syntax-table))
+ 	(punctuation (car (string-to-syntax "."))))
+     ;; Convert all punctuation entries to symbol.
+     (map-char-table (lambda (c syntax) 
+ 		      (when (eq (car syntax) punctuation)
+ 			(modify-syntax-entry c "_" table)
+ 			))
+ 		    table)
+     (mapc
+      (lambda (c)
+        (modify-syntax-entry c "." table))
+      '(?/
+        ?: ?\\
+        ))
+     table)
+   "Syntax table to be used in minibuffer for reading file name.")
+ 
  ;; minibuffer-completing-file-name is a variable used internally in minibuf.c
  ;; to determine whether to use minibuffer-local-filename-completion-map or
  ;; minibuffer-local-completion-map.  It shouldn't be exported to Elisp.
***************
*** 2065,2071 ****
                                 (lambda ()
                                   (with-current-buffer
                                       (window-buffer (minibuffer-selected-window))
! 				   (read-file-name--defaults dir initial)))))
                        (completing-read prompt 'read-file-name-internal
                                         pred mustmatch insdef
                                         'file-name-history default-filename)))
--- 2083,2091 ----
                                 (lambda ()
                                   (with-current-buffer
                                       (window-buffer (minibuffer-selected-window))
! 				   (read-file-name--defaults dir initial))))
! 			  (set-syntax-table minibuffer-local-filename-syntax)
! 			  )
                        (completing-read prompt 'read-file-name-internal
                                         pred mustmatch insdef
                                         'file-name-history default-filename)))






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer
  2011-09-15  8:39 bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer Masatake YAMATO
  2011-09-15 13:03 ` Stefan Monnier
@ 2012-04-12 19:52 ` Lars Magne Ingebrigtsen
  2012-04-13  1:30   ` Masatake YAMATO
  1 sibling, 1 reply; 6+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-04-12 19:52 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: 9511

Masatake YAMATO <yamato@redhat.com> writes:

> This is a request for merge a patch to official GNU Emacs source tree.
> Following patch adds a function to move the point to / with
> C-M-f and C-M-b when reading a filename from minibuffer.

Isn't this virtually the same as `M-f'/`M-b' in most cases?

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer
  2012-04-12 19:52 ` Lars Magne Ingebrigtsen
@ 2012-04-13  1:30   ` Masatake YAMATO
  2012-04-13 21:35     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Masatake YAMATO @ 2012-04-13  1:30 UTC (permalink / raw)
  To: larsi; +Cc: 9511

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
> Masatake YAMATO <yamato@redhat.com> writes:
> 
>> This is a request for merge a patch to official GNU Emacs source tree.
>> Following patch adds a function to move the point to / with
>> C-M-f and C-M-b when reading a filename from minibuffer.
> 
> Isn't this virtually the same as `M-f'/`M-b' in most cases?

M-f / M-b captures periods used in extension(suffix).

Consider 

	 /tmp/foo.el<point>

If you type M-b, you will see

	 /tmp/foo.<point>el

What I want with M-C-b is

	 /tmp/<point>foo.el

I think read-file-name should know path separator defined by underlying
operating system.

Masatake YAMATO
 
> -- 
> (domestic pets only, the antidote for overdose, milk.)
>   bloggy blog http://lars.ingebrigtsen.no/





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer
  2012-04-13  1:30   ` Masatake YAMATO
@ 2012-04-13 21:35     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2012-04-13 21:35 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: 9511

Masatake YAMATO <yamato@redhat.com> writes:

> Consider 
>
> 	 /tmp/foo.el<point>
>
> If you type M-b, you will see
>
> 	 /tmp/foo.<point>el
>
> What I want with M-C-b is
>
> 	 /tmp/<point>foo.el

Yeah, that seems useful.  I'm applying your patch with some white-space
cleanups.

-- 
(domestic pets only, the antidote for overdose, milk.)
  http://lars.ingebrigtsen.no  *  Sent from my Rome





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-04-13 21:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-15  8:39 bug#9511: Moving the point to / with C-M-f and C-M-b when reading a filename from minibuffer Masatake YAMATO
2011-09-15 13:03 ` Stefan Monnier
2011-09-15 14:05   ` Masatake YAMATO
2012-04-12 19:52 ` Lars Magne Ingebrigtsen
2012-04-13  1:30   ` Masatake YAMATO
2012-04-13 21:35     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).