ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Latest contextnl.el
@ 1999-05-31 16:59 Berend de Boer
  0 siblings, 0 replies; only message in thread
From: Berend de Boer @ 1999-05-31 16:59 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: multipart/mixed;, Size: 18801 bytes --]

This is a multi-part message in MIME format.

------=_NextPart_000_00AC_01BEAB97.BB59F9C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hai All,

Here the latest contextnl.el and a README (for Hans).

Groetjes,

Berend. (-:

------=_NextPart_000_00AC_01BEAB97.BB59F9C0
Content-Type: application/octet-stream;
	name="contextnl.el"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="contextnl.el"

;;; expands tex-mode.el, distributed with Emacs 20.3, with
;;; ConTeXt awareness.
;;; Also has some functionality to make tex-mode more
;;; usable on systems without a unix shell like Win98 or NT.

;;; Created by Berend de Boer <berend@pobox.com> on 1999-may-12
;;; Last changed on 1999-may-28.

;;; Note: had to override tex-mode and tex-send-command, so be aware
;;; for updates in tex-mode.el that change these commands. They have
;;; to be copied to this file also.

;;; Usage:
;;; put contextnl in your emacs site-lisp path, for example:
;;;   /usr/local/share/emacs/site-lisp
;;; or
;;;   c:\emacs\site-lisp
;;;
;;; add this command to your ~/.emacs file:
;;;   (load "contextnl")
;;;
;;; place this in your ~/.emacs file if you want context mode to be
;;; your default tex-mode:
;;;   (setq tex-default-mode 'context-mode)
;;;
;;; if you run a msdos shell (you use Win98/NT) to compile your
;;; tex/context files, this setting might be useful:
;;;   (setq tex-using-dosshell t)

(require 'tex-mode)

;;;###autoload
(defcustom tex-using-dosshell nil
  "If t then assume dosshell so do path conversion from / to \\"
  :type 'boolean
  :group 'tex-run)

;;;###autoload
(defcustom context-run-command "context -interaction=3Derrorstopmode *"
  "*Command used to run ConTeXt subjob.
ConTeXt Mode sets `tex-command' to this string.
See the documentation of that variable."
  :type 'string
  :group 'tex-run)

(defvar standard-context-block-names
  '("achtergrond"      "buffer"           "citaat"           =
"combinatie"
		"encoding"         "formule"          "gegeven"          =
"hoofdteksten"
    "inleidingen"      "kadertekst"       "kantlijn"         "kleur"
    "kolommen"         "legenda"          "lokalevoetnoten"  "mapping"
		"margeblok"        "mode"             "notmode"          "omgeving"
		"onderdeel"        "opelkaar"         "opsomming"        =
"positioneren"
		"produkt"          "project"          "raster"           "regel"
		"regelcorrectie"   "regelnummeren"    "regels"           "register"
		"smaller"          "standaardopmaak"	"tabel"            "tabulatie"
    "tekst"            "typen"            "uitleidingen"     "uitlijnen"
    "uitstellen"       "verbergen")
  "Standard ConTeXt block names.")

;;;###autoload
(defcustom context-block-names nil
  "*User defined ConTeXt block names.
Combined with `standard-context-block-names' for minibuffer completion."
  :type '(repeat string)
  :group 'tex-run)

;;;###autoload
(defcustom tex-texutil-references-command "texutil --references"
  "*Command used to create a ConTeXt tuo file
If this string contains an asterisk (`*'), that is replaced by the file =
name;
otherwise, the file name, preceded by blank, is added at the end."
  :type 'string
  :group 'tex-run)

;;;###autoload
(defcustom tex-texutil-figures-command "texutil --figures"
  "*Command used to create a ConTeXt texutil.tuf file which contains
size information about pictures in the current directory."
  :type 'string
  :group 'tex-run)

;;;###autoload
(defcustom tex-texutil-figures-command "texutil --figures *.png"
  "*Command used to create a ConTeXt texutil.tuf file which contains
size information about all .png files in the current directory."
  :type 'string
  :group 'tex-run)

(defcustom context-imenu-indent-string "."
  "*String to add repeated in front of nested sectional units for Imenu.
An alternative value is \" . \", if you use a font with a narrow =
period."
  :type 'string
  :group 'tex)

(defun context-imenu-create-index ()
  "Generates an alist for imenu from a ConTeXt buffer."
  (let (i0 menu case-fold-search)
    (save-excursion
      ;; Find the top-most level in this file but don't allow it to be
      ;; any deeper than "section" (which is top-level in an article).
      (goto-char (point-min))
      (if (search-forward-regexp "\\\\deel\\*?[ \t]*{" nil t)
					(setq i0 0)
				(if (search-forward-regexp "\\\\hoofdstuk\\*?[ \t]*{" nil t)
						(setq i0 1)
					(setq i0 2)))
		=09
      ;; Look for chapters and sections.
      (goto-char (point-min))
      (while (search-forward-regexp
							"\\\\\\(deel\\|hoofdstuk\\|paragraaf\\|subparagraaf\\|\
subsubparagraaf\\|subsubsubparagraaf\\|subsubsubsubparagraaf\\)\\*?[ =
\t]*{" nil t)
				(let ((start (match-beginning 0))
							(here (point))
							(i (cdr (assoc (buffer-substring-no-properties
															(match-beginning 1)
															(match-end 1))
														 '(("deel" . 0)=20
															 ("hoofdstuk" . 1)
															 ("paragraaf" . 2)=20
															 ("subparagraaf" . 3)
															 ("subsubparagraaf" . 4)
															 ("subsubsubparagraaf" . 5)=20
															 ("subsubsubsubparagraaf" . 6))))))
					(backward-char 1)
					(condition-case err
							(progn
								;; Using sexps allows some use of matching {...} inside
								;; titles.
								(forward-sexp 1)
								(setq menu
											(cons (cons (concat (apply 'concat
																								 (make-list
																									(max 0 (- i i0))
																									context-imenu-indent-string))
																					(buffer-substring-no-properties
																					 here (1- (point))))
																	start)
														menu))
								)
						(error nil))))
		=09
      ;; Look for included material.
      (goto-char (point-min))
      (while (search-forward-regexp
							"\\\\\\(input\\|typefile\\)[ \t]*{\\([^}\n]+\\)}"
							nil t)
				(setq menu
							(cons (cons (concat "<<" (buffer-substring-no-properties
																				(match-beginning 2)
																				(match-end 2))
																	(if (=3D (char-after (match-beginning 1)) ?b)
																			".bbl"
																		".tex"))
													(match-beginning 0))
										menu)))
		=09
      ;; Look for \startinleidingen, \starthoofdteksten, \startbijlagen, =
and \startuitleidingen.
      (goto-char (point-min))
      (while (search-forward-regexp
							=
"\\\\\\(startinleidingen\\|starthoofdteksten\\|startbijlagen\\|startuitle=
idingen\\)\\b"
							nil t)
				(setq menu
							(cons (cons "--" (match-beginning 0))
										menu)))
		=09
      ;; Sort in increasing buffer position order.
      (sort menu (function (lambda (a b) (< (cdr a) (cdr b)))))
			)
		)
	)

;;; I needed to override tex-mode, else always plain-tex-mode would be =
used
;;; when loading a ConTeXt file. Now if you set tex-default-mode to
;;; context-mode, ConTeXt is the default when it is not a LaTeX file.
;;;
;;; This would be a lot simpler if we just used a regexp search,
;;; but then it would be too slow.
;;;###autoload
(defun tex-mode ()
  "Major mode for editing files of input for TeX, LaTeX, or SliTeX.
Tries to determine (by looking at the beginning of the file) whether
this file is for plain TeX, LaTeX, or SliTeX and calls =
`tex-default-mode',
`latex-mode', or `slitex-mode', respectively.  If it cannot be =
determined,
such as if there are no commands in the file, the value of =
`tex-default-mode'
says which mode to use."
  (interactive)
  (let (mode slash comment)
    (save-excursion
      (goto-char (point-min))
      (while (and (setq slash (search-forward "\\" nil t))
		  (setq comment (let ((search-end (point)))
				  (save-excursion
				    (beginning-of-line)
				    (search-forward "%" search-end t))))))
      (if (and slash (not comment))
	  (setq mode (if (looking-at =
"documentstyle\\|documentclass\\|begin\\b\\|NeedsTeXFormat{LaTeX")
                         (if (looking-at
			      "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
                             'slitex-mode
                           'latex-mode)
		       (funcall tex-default-mode)))))
    (if mode (funcall mode)
      (funcall tex-default-mode))))

;;;###autoload
(defun context-mode ()
  "Major mode for editing files of input for ConTeXt.
Makes $ and } display the characters they match.
Makes \" insert `` when it seems to be the beginning of a quotation,
and '' when it appears to be the end; it inserts \" only after a \\.

Use \\[tex-region] to run ConTeXt on the current region, plus a =
\"header\"
copied from the top of the file (containing macro definitions, etc.),
running ConTeXt under a special subshell.  \\[tex-buffer] does the=20
whole buffer.
\\[tex-file] saves the buffer and then processes the file.
\\[tex-print] prints the .dvi file made by any of these.
\\[tex-view] previews the .dvi file made by any of these.
\\[tex-bibtex-file] runs bibtex on the file of the current buffer.

Use \\[validate-tex-buffer] to check buffer for paragraphs containing
mismatched $'s or braces.

Special commands:
\\{tex-mode-map}

Mode variables:
context-run-command
	Command string used by \\[tex-region] or \\[tex-buffer].
tex-directory
	Directory in which to create temporary files for TeX jobs
	run by \\[tex-region] or \\[tex-buffer].
tex-dvi-print-command
	Command string used by \\[tex-print] to print a .dvi file.
tex-alt-dvi-print-command
	Alternative command string used by \\[tex-print] (when given a prefix
	argument) to print a .dvi file.
tex-dvi-view-command
	Command string used by \\[tex-view] to preview a .dvi file.
tex-show-queue-command
	Command string used by \\[tex-show-print-queue] to show the print
	queue that \\[tex-print] put your job on.

Entering ConTeXt-tex mode runs the hook `text-mode-hook', then the hook
`tex-mode-hook', and finally the hook `context-mode-hook'.  When the
special subshell is initiated, the hook `tex-shell-hook' is run."

  (interactive)
  (tex-common-initialization)
  (setq mode-name "ConTeXt")
  (setq major-mode 'tex-mode)
  (setq tex-command context-run-command)
  (setq tex-start-of-header "%\\*\\*start of header")
  (setq tex-end-of-header "\\\\starttekst")
  (setq tex-trailer "\\stoptekst\n")
  ;; A line containing just $$ is treated as a paragraph separator.
  ;; A line starting with $$ starts a paragraph,
  ;; but does not separate paragraphs if it has more stuff on it.
  (setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\
[ \t]*\\\\start[a-z]*\\|[ \t]*\\\\stop[a-z]*\\|\
\\\\plaats[a-z]*\\|\\\\\\[\\|\\\\\\]\\|\
\\\\hoofdstuk\\>\\|\\\\paragraaf\\>\\|\
\\\\subparagraaf\\>\\|\\\\subsubparagraaf\\>\\|\
\\\\subsubsubparagraaf\\>\\|\\\\subsubsubsubparagraaf\\>\\|\
[ \t]*\\\\som\\>\\|\\\\noindent\\>\\|\
\\\\pagina\\>\\|\\\\voetnoot\\>")
  (setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\
[ \t]*\\\\start[a-z]*\\|[ \t]*\\\\stop[a-z]*\\|\
\\\\plaats[a-z]*\\|\\\\\\[\\|\\\\\\]\\|\
\\\\hoofdstuk\\>\\|\\\\paragraaf\\>\\|\
\\\\subparagraaf\\>\\|\\\\subsubparagraaf\\>\\|\
\\\\subsubsubparagraaf\\>\\|\\\\subsubsubsubparagraaf\\>\\|\
\\([ \t]*\\\\som\\)[ \t]*\\($\\|%\\)")
  (make-local-variable 'imenu-create-index-function)
  (setq imenu-create-index-function 'context-imenu-create-index)
  (make-local-variable 'fill-nobreak-predicate)
  (setq fill-nobreak-predicate 'context-fill-nobreak-predicate)
  (define-key tex-mode-map "\C-c\C-t" 'tex-texutil-references-file)
  (define-key tex-mode-map [menu-bar tex tex-texutil-references-file]
    '("TeXUtil --references" . tex-texutil-references-file))
  (define-key tex-mode-map "\C-c\C-o" 'tex-context-block)
  (define-key tex-mode-map "\C-c\C-e" 'tex-close-context-block)
  (define-key tex-mode-map "\C-c\C-u" =
'tex-goto-last-unclosed-context-block)
  (run-hooks 'text-mode-hook 'tex-mode-hook 'context-mode-hook))

;;;###autoload
(defalias 'ConTeXt-mode 'context-mode)

;; This function is used as the value of fill-nobreak-predicate
;; in ConTeXt mode.  Its job is to prevent line-breaking inside
;; of a \type construct.
(defun context-fill-nobreak-predicate ()
  (let ((opoint (point))
	inside)
    (save-excursion
      (save-restriction
	(beginning-of-line)
	(narrow-to-region (point) opoint)
	(while (re-search-forward "\\\\type\\(.\\)" nil t)
	  (unless (re-search-forward (regexp-quote (match-string 1)) nil t)
	    (setq inside t)))))
    inside))

;;; Like tex-insert-braces, but for ConTeXt.
(define-skeleton tex-context-block
  "Create a matching pair of lines \\startNAME[OPT] and \\stopNAME at =
point.
Puts point on a blank line between them."
  (completing-read "ConTeXt block name: "
		   (mapcar 'list
			   (append standard-context-block-names
				   latex-block-names)))
  "\\start" str
  ?\[ (skeleton-read "[options]: ") & ?\] | -1
 \n
  _ \n
  "\\stop" str)

(defun tex-last-unended-start ()
  "Leave point at the beginning of the last `\\start...' that is =
unstopped."
  (while (and (re-search-backward "\\\\start[a-z]*\\|\\\\stop[a-z]*")
              (looking-at "\\\\stop[a-z]*"))
    (tex-last-unended-start)))

(defun tex-close-context-block ()
  "Creates an \\stop... to match the last unclosed \\start...."
  (interactive "*")
  (let ((new-line-needed (bolp))
	text indentation)
    (save-excursion
      (condition-case nil
          (tex-last-unended-start)
        (error (error "Couldn't find unended \\start")))
      (setq indentation (current-column))
      (re-search-forward "\\\\start[a-z]*")
			(setq text (buffer-substring (+ (match-beginning 0) 6) (match-end =
0))))
    (indent-to indentation)
    (insert "\\stop" text)
    (if new-line-needed (insert ?\n))))

(defun tex-goto-last-unclosed-context-block ()
  "Move point to the last unclosed \\start....
Mark is left at original location."
  (interactive)
  (let ((spot))
    (save-excursion
      (condition-case nil
          (tex-last-unended-start)
        (error (error "Couldn't find unended \\start")))
      (setq spot (point)))
    (push-mark)
    (goto-char spot)))

(defun tex-texutil-references-file ()
  "Run texutil --references on the current buffer's file."
  (interactive)
  (if (tex-shell-running)
      (tex-kill-job)
    (tex-start-shell))
  (let (shell-dirtrack-verbose
	(tex-out-file
         (tex-append (file-name-nondirectory (buffer-file-name)) ""))
	(file-dir (file-name-directory (buffer-file-name))))
    (tex-send-command tex-shell-cd-command file-dir)
    (tex-send-command tex-texutil-references-command tex-out-file))
  (tex-display-shell))

;; enable the following command

(defun tex-send-command (command &optional file background)
  "Send COMMAND to TeX shell process, substituting optional FILE for *.
Do this in background if optional BACKGROUND is t.  If COMMAND has no *,
FILE will be appended, preceded by a blank, to COMMAND.  If FILE is nil, =
no
substitution will be made in COMMAND.  COMMAND can be any expression =
that
evaluates to a command string.

Return the process in which TeX is running."
  (save-excursion
		(if (and file tex-using-dosshell)=20
				 (while (string-match "/" file)
					 (aset file (match-beginning 0) ?\\)))
		(if (and file tex-using-dosshell)=20
				(setq file (concat "\"" file "\"")))
		(let* ((cmd (eval command))
					 (proc (or (get-process "tex-shell") (error "No TeX subprocess")))
					 (buf (process-buffer proc))
					 (star (string-match "\\*" cmd))
					 (string
							(concat
							 (if file
									 (if star (concat (substring cmd 0 star)
																		file (substring cmd (1+ star)))
										 (concat cmd " " file))
								 cmd)
							 (if background "&" ""))))
			;; Switch to buffer before checking for subproc output in it.
			(set-buffer buf)
			;; If text is unchanged since previous tex-send-command,
			;; we haven't got any output.  So wait for output now.
			(if (=3D (buffer-modified-tick buf) tex-send-command-modified-tick)
					(accept-process-output proc))
			(goto-char (process-mark proc))
			(insert string)
			(comint-send-input)
			(setq tex-send-command-modified-tick (buffer-modified-tick buf))
			proc)))

------=_NextPart_000_00AC_01BEAB97.BB59F9C0
Content-Type: application/octet-stream;
	name="contextnl.README"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="contextnl.README"

README for contextnl.nl

* INSTALLATION *

1. Where to put contextnl.el:

	 Put contextnl in your emacs site-lisp path.
	 On Unix systems this probably is:

			 /usr/local/share/emacs/site-lisp

	 On Win9x or NT systems this is a directory like:

	    c:\emacs\site-lisp

2. Where to put the command to load this mode?

	 The new context mode is not automagically recognized. You have to
	 load it in your ~/.emacs file. Put the following command in this file:

	    (load "contextnl")

	 For xemacs based systems you might want to put it in ~/.xemacs-options

3. Is it compatible with AucTeX?

	 IT'S NOT! This mode extends the tex-mode.el distributed with
	emacs. AucTeX is a separate and distinct package.

4. Are there more options?

	 Yes, you might want to add (some of) the following commands after
	 the (load "contextnl") command:

	 a. Make ConTeXt your default mode (else you will get plain-tex-mode
	    for new and for existing ConTeXt files):

					(setq tex-default-mode 'context-mode)

	 b. If you run an msdos shell (you use Win98/NT) to compile your
	    tex/context files, this setting might be useful:

					(setq tex-using-dosshell t)

			It translates forward slashes ('/') to backward slashes ('\') so
			directory changes work.

TIPS

Emacs is the world's best editor. In this section some tips what
ConTeXt mode can do for you.

1. You get new commands at the top of your TeX menu:

	 - run "texutil --references"
	 - and run context itself.

	 So you can compile within emacs itself.

2. ConTeXt-mode can create a context aware imenu. Load a ConTeXt file
   with some \hoofdstuk or \paragraaf commands and run:

	   imenu-menubar-add-index

	 (press M-x and type this command)

	 You get now a new menu entry called 'index'. Under this menu you
	 find your document structure so you can jump immediately to the
	 right chapter of (sub)paragraph!

3. ConTeXt-mode has ConTeXt are completions. If you are asked to type
   something, press the first few characters and press TAB.

4. M-q (fill-paragraph) is also ConTeXt-aware.

5. ConTeXt-mode can insert ConTeXt-aware blocks like \startopsomming
   .. \stopopsomming.

	 Press C-c C-o and type 'opsomming' (or type 'ops' and press TAB).
	 Next you are asked for any options. Just press RET. Now a

	 \startopsomming
	 _
	 \stopopsomming

	 block is inserted and the cursor is at the correct point.

6. Automatically insert the correct \stop... for the preceding
   \start... command?
	 Type:

				\startopsomming

	 and press RET. Now press C-c C-e and you get a \stopopsomming below
	 it.

------=_NextPart_000_00AC_01BEAB97.BB59F9C0--


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-05-31 16:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-31 16:59 Latest contextnl.el Berend de Boer

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).