From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Hansen Newsgroups: gmane.emacs.help Subject: Re: Insert appropriate line-end character (like ';' for C*) Date: Wed, 11 Jun 2008 22:58:03 +0200 Organization: disorganized Message-ID: <87d4mnadus.fsf@localhorst.mine.nu> References: <333b2bc9-8ad4-4f0e-b508-eb143fd9d2fe@c58g2000hsc.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1213218614 10868 80.91.229.12 (11 Jun 2008 21:10:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Jun 2008 21:10:14 +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 Jun 11 23:10:57 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K6XZa-0001lm-7l for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jun 2008 23:09:38 +0200 Original-Received: from localhost ([127.0.0.1]:50181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6XYm-0008CO-Mc for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jun 2008 17:08:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6XYQ-00088r-5j for help-gnu-emacs@gnu.org; Wed, 11 Jun 2008 17:08:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6XYP-00086w-Ic for help-gnu-emacs@gnu.org; Wed, 11 Jun 2008 17:08:25 -0400 Original-Received: from [199.232.76.173] (port=50496 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6XYP-00086m-81 for help-gnu-emacs@gnu.org; Wed, 11 Jun 2008 17:08:25 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:47779 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K6XYO-0006ri-Rn for help-gnu-emacs@gnu.org; Wed, 11 Jun 2008 17:08:25 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1K6XYH-00024z-Gd for help-gnu-emacs@gnu.org; Wed, 11 Jun 2008 21:08:17 +0000 Original-Received: from e178027049.adsl.alicedsl.de ([85.178.27.49]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 Jun 2008 21:08:17 +0000 Original-Received: from david.hansen by e178027049.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 Jun 2008 21:08:17 +0000 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 50 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e178027049.adsl.alicedsl.de Mail-Copies-To: nobody User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:KlIyZVrM7AdW42z1ojc9TrieVE4= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:54745 Archived-At: On Wed, 11 Jun 2008 12:09:58 -0700 (PDT) Josh wrote: > On Jun 11, 12:17 am, David Hansen wrote: > >> `;' is not a "line-end" character in C but a "end-of-statement" >> character.  Not even a full featured C parser can know if you want to >> continue the statement on the next line or not: >> >> foo = bar () >>         && baz (); > > Ok, end of statement is what I was looking for. Thanks. > > I know that emacs can't possibly know what my intention is, but it > _can_ know what the appropriate end-of-statement character is for the > current context. All I'm looking for is a command that will insert > that character; I'll take care of making sure it's inserted at the > appropriate time myself. > > To be more clear, I'm trying to replecate a behavior in TextMate. In > TextMate, if you hit command-shift-return it adds the context- > appropriate end-of-statement character to the end of the current line, > creates a new line below it, and indents that new line. I can already > make Emacs do everything other than insert the end-of-statement > character, but that's only because I don't know how to programatically > determine what the correct character is. Well, set it manually (not tested). Emacs can not possibly know about all statement delimiters of all languages out there: ;;; Add more either here or using ;;; (setq dh-eos-alist (cons '(mode . "str") dh-eos-alist) (defvar dh-eos-alist '((c-mode . ";") (c++-mode . ";") (java-mode . ";"))) (defun dh-insert-eos () (interactive) (let ((eos (assq major-mode dh-eos-alist))) (insert (if eos (cdr eos) "")) ;; Change this if you don't want auto-indent. (newline-and-indent))) ;; May be problematic outside of X. Use the output of C-h k as an ;; argument to `kbd' for "weird" keys. (global-set-key (kbd "") #'dh-insert-eos) David