ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* For all those who don't want to wait for tek :-))
@ 1999-05-26 18:44 Berend de Boer
  0 siblings, 0 replies; only message in thread
From: Berend de Boer @ 1999-05-26 18:44 UTC (permalink / raw)


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

This is a multi-part message in MIME format.

------=_NextPart_000_0050_01BEA7B8.86CF82C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hai All,

For the best editor (yes Hans, just try it), here a context mode, only dutch
supported at the moment, if you are interested in english or german modes,
just let me know.

Just save contextnl.el in your site-lisp directory and add the following to
your .emacs file:

(load "contextnl")
(setq tex-default-mode 'context-mode)

Groetjes,

Berend. (-:

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

;;; expands tex-mode.el to provide ConTeXt commands

;;; Created by Berend de Boer, 1999-may-12

;;; had to overrides tex-mode, so be aware for updates in tex-mode.el
;;; that change tex-mode

;;; Usage:
;;; add this command to your ~/.emacs file
;;;   (load "contextnl")
;;;
;;; set this if you want context mode to be your default
;;;   (setq tex-default-mode 'context-mode)

(require 'tex-mode)

;;;###autoload
(defcustom context-run-command "context *"
  "*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)

;;;###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)))

      ;; 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) ("hoofdstuk" . 1)
			       ("paragraaf" . 2) ("subparagraaf" . 3)
			       ("subsubparagraaf" . 4)
			       ("subsubsubparagraaf" . 5) ("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))))

      ;; Look for included material.
      (goto-char (point-min))
      (while (search-forward-regexp
	      "\\\\\\(include\\|input\\|verbatiminput\\|bibliography\\)\
[ \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)))

      ;; Look for \frontmatter, \mainmatter, \backmatter, and \appendix.
      (goto-char (point-min))
      (while (search-forward-regexp
	      =
"\\\\\\(startinleidingen\\|starthoofdteksten\\|startuitleidingen\\|append=
ix\\)\\b"
	      nil t)
	(setq menu
	      (cons (cons "--" (match-beginning 0))
		    menu)))

      ;; Sort in increasing buffer position order.
      (sort menu (function (lambda (a b) (< (cdr a) (cdr b))))))))

;;; 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 `plain-tex-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]*\\$\\$\\|\
\\\\start[a-z]*\\|\\\\stop[a-z]*\\|\\\\plaats[a-z]*\\|\\\\\\[\\|\\\\\\]\\=
|\
\\\\hoofdstuk\\>\\|\\\\paragraaf\\>\\|\
\\\\subparagraaf\\>\\|\\\\subsubparagraaf\\>\\|\
\\\\subsubsubparagraaf\\>\\|\\\\subsubsubsubparagraaf\\>\\|\
\\\\som\\>\\|\\\\noindent\\>\\|\
\\\\pagina\\>\\|\\\\voetnoot\\>")
  (setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\
\\\\start[a-z]*\\|\\\\stop[a-z]*\\|\\\\plaats[a-z]*\\|\\\\\\[\\|\\\\\\]\\=
|\
\\\\hoofdstuk\\>\\|\\\\paragraaf\\>\\|\
\\\\subparagraaf\\>\\|\\\\subsubparagraaf\\>\\|\
\\\\subsubsubparagraaf\\>\\|\\\\subsubsubsubparagraaf\\>\\|\
\\(\\\\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))
  (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))

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

(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 file (while (string-match "/" file)
								(aset file (match-beginning 0) ?\\)))
		(if file (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_0050_01BEA7B8.86CF82C0--


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

only message in thread, other threads:[~1999-05-26 18:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-26 18:44 For all those who don't want to wait for tek :-)) 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).