From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Line editor with dynamic prompt Date: Wed, 29 Oct 2014 08:46:05 +0100 Organization: Informatimago Message-ID: <87zjcf48ua.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1414569052 17245 80.91.229.3 (29 Oct 2014 07:50:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Oct 2014 07:50:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 29 08:50:46 2014 Return-path: Envelope-to: geh-help-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 1XjO1l-0008J5-IO for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Oct 2014 08:50:45 +0100 Original-Received: from localhost ([::1]:43699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjO1l-0007lT-96 for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Oct 2014 03:50:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjO1L-0007aC-6A for help-gnu-emacs@gnu.org; Wed, 29 Oct 2014 03:50:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XjO1F-0007cU-3K for help-gnu-emacs@gnu.org; Wed, 29 Oct 2014 03:50:19 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:44664) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjO1E-0007cP-Sy for help-gnu-emacs@gnu.org; Wed, 29 Oct 2014 03:50:13 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XjO1D-00084O-Ez for help-gnu-emacs@gnu.org; Wed, 29 Oct 2014 08:50:11 +0100 Original-Received: from amontsouris-654-1-245-99.w90-44.abo.wanadoo.fr ([90.44.188.99]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 29 Oct 2014 08:50:11 +0100 Original-Received: from pjb by amontsouris-654-1-245-99.w90-44.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 29 Oct 2014 08:50:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 108 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-654-1-245-99.w90-44.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:NWQ2Y2U4ZGVjODZjYTMxMDhjNmE0YmFkYzY5MzA3MTIxODkyM2RiNg== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100644 Archived-At: Whitfield Diffie writes: > The attached program --- whose calling sequence is > > (lineedit prompt-base starting-string position-in-string) > > displays the length of the string and the position of point in the > string as part of the prompt; it changes as point moves or the string > is edited. > > Does anyone know how to do this without having to write the line > editor by hand? Yes, somebody knows how to do it without having to write the line editor by hand. The question is why you need to input the string from the minibuffer. This is an operation that is modal. Emacs is a mostly modless editor and user interface framework. The idea is to let the user choose what he is editing at any time. When the user types some key chord that correspond to commands that require more information, there may be some modal interaction and editing occuring in the minibuffer. For example, C-x C-f will require the user to edit the path of the file to be visited in the minibuffer. For those small modal editing operations, it has not been deemed useful to provide the length of input and cursor position. If you let the user edit this string in a normal buffer, then you can use the minor modes line-number-mode and column-number-mode to see the current line and column displayed in the mode line. I suppose you could write a similar minor mode that would also display the line length. To process the input you would bind a command to a key, perhaps RET or C-RET or something else, and this command could collect the string from the buffer Otherwise, you may perhaps do something. Those modal operations (read-from-minibufffer, read-string, read-file-name etc) are implemented in C, you wouldn't want to modify them (you'd have to recompile emacs). You can use them with the minibuffer-with-setup-hook to configure the minibuffer however you want. For example: (defun minibuffer-meat () (interactive) (local-set-key (kbd "!") (lambda () (interactive) (insert "!!!")))) (minibuffer-with-setup-hook (function minibuffer-meat) (read-string "TRY> ")) C-u C-e C-x Hello world! RET returns: "Hello world!!!" You can also use directly minibuffer-setup-hook and minibuffer-exit-hook. In those hooks, you could set things up so that the minibuffer contents (probably not the prompt) is edited to contain the position and length of the string, or you could display it in the mode line. With: (defun my-minibuffer-postcommand () (save-excursion (message "length = %d" (- (progn (end-of-line) (point)) (progn (beginning-of-line) (point)))))) (defun my-minibuffer-setup-meat () (add-hook 'post-command-hook 'my-minibuffer-postcommand)) (defun my-minibuffer-exit-meat () (remove-hook 'post-command-hook 'my-minibuffer-postcommand)) (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-meat) (add-hook 'minibuffer-exit-hook 'my-minibuffer-exit-meat) (minibuffer-with-setup-hook (function minibuffer-meat) (read-string "TRY> ")) C-u C-x C-e hello SPC RET will display in *Message* (and also in the minibuffer, oops): length = 0 length = 1 length = 2 length = 3 length = 4 length = 5 length = 6 and will return: "hello " (remove-hook 'minibuffer-setup-hook 'my-minibuffer-setup-meat) (remove-hook 'minibuffer-exit-hook 'my-minibuffer-exit-meat) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk