From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/27284 Path: news.gmane.org!not-for-mail From: "Johan Sandblom" Newsgroups: gmane.comp.tex.context Subject: Re: emacs lisp for context in AucTeX Date: Thu, 20 Apr 2006 14:23:41 +0200 Message-ID: <97a06f070604200523h37a656ceh990b2565db50a85f@mail.gmail.com> References: Reply-To: johan.sandblom@ki.se, mailing list for ConTeXt users NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1145535850 20128 80.91.229.2 (20 Apr 2006 12:24:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 20 Apr 2006 12:24:10 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Thu Apr 20 14:23:56 2006 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by ciao.gmane.org with esmtp (Exim 4.43) id 1FWYCP-0001DW-Bx for gctc-ntg-context-518@m.gmane.org; Thu, 20 Apr 2006 14:23:53 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 651DF1276B; Thu, 20 Apr 2006 14:23:52 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 06683-03; Thu, 20 Apr 2006 14:23:48 +0200 (CEST) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 87F4F12772; Thu, 20 Apr 2006 14:23:47 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id BAE6512772 for ; Thu, 20 Apr 2006 14:23:44 +0200 (CEST) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 04855-05 for ; Thu, 20 Apr 2006 14:23:43 +0200 (CEST) Original-Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.228]) by ronja.ntg.nl (Postfix) with SMTP id AC5591276B for ; Thu, 20 Apr 2006 14:23:42 +0200 (CEST) Original-Received: by wproxy.gmail.com with SMTP id i5so397338wra for ; Thu, 20 Apr 2006 05:23:41 -0700 (PDT) Original-Received: by 10.65.43.9 with SMTP id v9mr211675qbj; Thu, 20 Apr 2006 05:23:41 -0700 (PDT) Original-Received: by 10.64.232.7 with HTTP; Thu, 20 Apr 2006 05:23:41 -0700 (PDT) Original-To: "mailing list for ConTeXt users" In-Reply-To: Content-Disposition: inline X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.7 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:27284 Archived-At: Thank you for this. I have written the following much more amateurish emacs lisp code in order to make it easier to enter natural tables and flowcharts. Perhaps someone may find it useful or can suggest improvements. I also added some keybindings for them. Johan (defun context-insert-nattab (rows columns) ;; Johan Sandblom 060128 "Insert a TABLE skeleton" (interactive "nNumber of rows: \nnNumber of columns: \n") (newline) (insert "\\bTABLE\n\\setupTABLE\[\]\n") ;; First a TABLE header (insert "\\bTABLEhead\n\\bTR\\bTH \\eTH\n") (let ((column 1)) (while (< column (- columns 1)) (insert " \\bTH \\eTH\n") (setq column (1+ column)))) (insert " \\bTH \\eTH\\eTR\n\\eTABLEhead\n\\bTABLEbody\n") ;; The rows and columns (let ((row 1)) (while (<= row rows) (insert "\\bTR\\bTD \\eTD\n") ;; The let expression makes sure that each loop starts at the ;; right place (let ((column 1)) (while (< column (- columns 1)) (insert " \\bTD \\eTD\n") (setq column (1+ column))) (insert " \\bTD \\eTD\\eTR\n") (setq row (1+ row)))) (insert "\\eTABLEbody\n\\eTABLE\n"))) (defun context-insert-nattab-row (columns) "Insert a row in a TABLE" (interactive "nNumber of columns: \n") (newline) (insert "\\bTR\\bTD \\eTD\n") (let ((column 1)) (while (< column (- columns 1)) (insert " \\bTD \\eTD\n") (setq column (1+ column))) (insert " \\bTD \\eTD\\eTR\n"))) (defun context-insert-nattab-column (&optional arg) "Insert a column in a TABLE" (interactive "P") (insert "\\bTD \\eTD") (indent-for-tab-command) (newline) (backward-char 5)) (defun context-insert-FLOW-cell (n) ;; Johan Sandblom 060128 "Insert a FLOWchart cell" (interactive "nNumber of cells: \n") (newline) (let ((x 1)) (while (<= x n) (insert "\\startFLOWcell\n") (insert " \\name {}\n") (insert " \\location {}\n") (insert " \\shape {action}\n") (insert " \\text {}\n") (insert " \\connection[rl]{}\n") (insert "\\stopFLOWcell\n") (setq x (1+ x))))) (add-hook 'ConTeXt-mode-hook '(lambda () (local-set-key "\C-c\C-fc" 'context-insert-FLOW-cells) (local-set-key "\C-cnr" 'context-insert-nattab-row) (local-set-key "\C-cnc" 'context-insert-nattab-column) (local-set-key "\C-cnn" 'context-insert-nattab) (local-set-key "$" 'start-context-math))) 2006/4/20, Sanjoy Mahajan : > I wrote the following emacs lisp for my .emacs and pass it on (no > copyright) in case others find it useful. I used variants for a decade > with the old tex mode, but just rewrote it for auctex and for context's > display math syntax (which deprecates $$...$$). > > The purpose: > > 1. If you type {, [, or (, the appropriate right delimiter is inserted > for you and the insertion point is placed between them. So I never > get unbalanced XYZ errors. If you think it's a misfeature, delete > the last three local-set-key's in the TeX-mode-hook. > > 2. Same feature if you type $ for inline math: you get $ here>$. The old tex-mode code would do the same on typing a second $, > so you'd get $$$$ for tex's display math. > > The code below will also do that, except in context mode. > > 3. In context mode, typing the second $ will gobble up preceding > whitespace and then insert > \placeformula\startformula > > \stopformula > > The whitespace-deletion code in start-context-math is a bit pathetic and > any improvements are welcome. I couldn't get re-search-backward to work > for me because it wouldn't match greedily (so it would gobble up one > space but not all of them, for example), so instead it just looks one > character at a time and deletes what it should. > > -Sanjoy > > > (defun insert-balanced (left right) > "Make a left, right delmiter pair and be poised to type inside of them." > (interactive) > (insert left) > (save-excursion > (insert right))) > > (defun start-context-math () > (interactive) > (let* ((start (max (point-min) (- (point) 1))) > (stop (min (point-max) (+ (point) 1)))) > ; if in the middle of a $$, turn inline math into context display math > (if (equal "$$" (buffer-substring-no-properties start stop)) > (progn > (delete-region start stop) ;get rid of the $$ > ; delete preceding spaces, if any > (while (and (< (point-min) (point)) > (equal (buffer-substring-no-properties (- (point) 1) > (point)) > " ")) > (backward-delete-char 1)) > ; delete a preceding newline, if any > (if (equal (buffer-substring-no-properties (- (point) 1) > (point)) > "\n") > (backward-delete-char 1)) > ; place > (insert "\n\\placeformula\\startformula\n") > (save-excursion (insert "\n\\stopformula"))) > ; else: just doing inline math > (insert-balanced ?\$ ?\$)))) > > (add-hook 'ConTeXt-mode-hook > '(lambda () > (local-set-key "$" 'start-context-math))) > > (add-hook 'TeX-mode-hook > '(lambda () > (local-set-key "$" > '(lambda () > (interactive) > (insert-balanced ?\$ ?\$))) > (local-set-key "{" > '(lambda () > (interactive) > (insert-balanced ?\{ ?\}))) > (local-set-key "[" > '(lambda () > (interactive) > (insert-balanced ?\[ ?\]))) > (local-set-key "(" > '(lambda () > (interactive) > (insert-balanced ?\( ?\)))))) > > _______________________________________________ > ntg-context mailing list > ntg-context@ntg.nl > http://www.ntg.nl/mailman/listinfo/ntg-context > -- Johan Sandblom N8, MRC, Karolinska sjh t +46851776108 17176 Stockholm m +46735521477 Sweden "What is wanted is not the will to believe, but the will to find out, which is the exact opposite" - Bertrand Russell