ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Sanjoy Mahajan <sanjoy@mrao.cam.ac.uk>
Subject: Re: emacs lisp for context in AucTeX
Date: Thu, 20 Apr 2006 11:15:52 -0400	[thread overview]
Message-ID: <E1FWasr-0006nS-3W@approximate.corpus.cam.ac.uk> (raw)
In-Reply-To: Your message of "Thu, 20 Apr 2006 14:23:41 +0200." <97a06f070604200523h37a656ceh990b2565db50a85f@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2511 bytes --]

Great.  Mojca suggested that I wikify my Emacs lisp.  It's now at
<http://wiki.contextgarden.net/Text_editor>.  Following that method ('a
method is a trick I use twice.' --Polya), I've put your elisp there too
-- hope that's okay.  I removed the

            (local-set-key "$" 'start-context-math)

so that your code can stand alone (in case people want one or the
other).

I had to change a few things at the end (some maybe because I'm using
GNU Emacs rather than XEmacs, not sure).  Below is the diff and I've
attached the resulting version.  Most of the trouble was in the
keybindings:

	    (local-set-key "\C-c\C-fc" 'context-insert-FLOW-cells)

doesn't work because C-c C-f is already defined as TeX-font, so it can't
be a prefix as well.  So I chose "\C-cnF".  Also the function name
needed an "s" at the end.  These two:

	    (local-set-key "\C-cnn" 'context-insert-nattab)
	    (local-set-key "\C-cnr" 'context-insert-nattab-row)

have a related problem, in that "\C-cn" is not a prefix yet, so "\C-cnn"
and "\C-cnr" are not valid sequences.  So I changed the first use of
"\C-cn" as a prefix to use define-key(), which seems to make a
prefix-map automatically as I eventually learnt by inspecting tex.el.
So:

	    (define-key (current-local-map) "\C-cnF" 'context-insert-FLOW-cells)
Then the following local-set-key's work.  As I say, this is on Emacs
21.4, and the tricks may be different on XEmacs.

-Sanjoy

--- a/tables.el	2006-04-20 10:46:16.000000000 -0400
+++ b/tables.el	2006-04-20 10:43:41.000000000 -0400
@@ -1,5 +1,5 @@
 (defun context-insert-nattab (rows columns)
-  ;; Johan Sandblom 060128
+  ;; Johan Sandblom 2006-01-28
   "Insert a TABLE skeleton"
   (interactive "nNumber of rows: \nnNumber of columns: \n")
   (newline)
@@ -44,8 +44,8 @@
  (newline)
  (backward-char 5))
 
-(defun context-insert-FLOW-cell (n)
- ;; Johan Sandblom 060128
+(defun context-insert-FLOW-cells (n)
+ ;; Johan Sandblom 2006-01-28
  "Insert a FLOWchart cell"
  (interactive "nNumber of cells: \n")
  (newline)
@@ -62,8 +62,7 @@
 
 (add-hook 'ConTeXt-mode-hook
          '(lambda ()
-	    (local-set-key "\C-c\C-fc" 'context-insert-FLOW-cells)
+	    (define-key (current-local-map) "\C-cnF" '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)))
+	    (local-set-key "\C-cnn" 'context-insert-nattab)))


[-- Attachment #2: revised natural tables elisp --]
[-- Type: text/plain, Size: 2151 bytes --]

(defun context-insert-nattab (rows columns)
  ;; Johan Sandblom 2006-01-28
  "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-cells (n)
 ;; Johan Sandblom 2006-01-28
 "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 ()
	    (define-key (current-local-map) "\C-cnF" '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)))

[-- Attachment #3: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

  reply	other threads:[~2006-04-20 15:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-20  1:44 Sanjoy Mahajan
2006-04-20 12:23 ` Johan Sandblom
2006-04-20 15:15   ` Sanjoy Mahajan [this message]
2006-04-20 15:45     ` Johan Sandblom
2006-04-20 15:48       ` Sanjoy Mahajan
2006-04-20 16:04         ` Johan Sandblom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1FWasr-0006nS-3W@approximate.corpus.cam.ac.uk \
    --to=sanjoy@mrao.cam.ac.uk \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).