From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "SMU mails" Newsgroups: gmane.emacs.devel Subject: Re: new awk-mode Date: Tue, 7 May 2002 21:47:43 -0500 Sender: emacs-devel-admin@gnu.org Message-ID: <005001c1f63a$bb04e200$48907781@gnorm> References: <200205041502.g44F2Gn01234@aztec.santafe.edu> <200205052331.g45NVha29859@rum.cs.yale.edu> <200205080012.g480CLW08634@rum.cs.yale.edu> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_004D_01C1F610.D189E770" X-Trace: main.gmane.org 1020826115 25490 127.0.0.1 (8 May 2002 02:48:35 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 8 May 2002 02:48:35 +0000 (UTC) Cc: "Stefan Monnier" , "Richard Stallman" , , , , "Alan Mackenzie" Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 175HVL-0006d1-00 for ; Wed, 08 May 2002 04:48:35 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 175HdG-000790-00 for ; Wed, 08 May 2002 04:56:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 175HUu-0001Ff-00; Tue, 07 May 2002 22:48:08 -0400 Original-Received: from post.cis.smu.edu ([129.119.64.23]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 175HUc-0001Ew-00; Tue, 07 May 2002 22:47:50 -0400 Original-Received: by post.cis.smu.edu (Smail-3.2.0.96 1997-Jun-2 #26) id ; Tue, 7 May 2002 21:47:47 -0500 (CDT) Original-To: "Stefan Monnier" , "Miles Bader" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:3698 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:3698 This is a multi-part message in MIME format. ------=_NextPart_000_004D_01C1F610.D189E770 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I am sure you mean the awk-mode.el I pasted. Before starting my work, I did not know some guy is now working on a new awk mode. The awk-mode.el itself seems unchanged for several years. In fact, my goal at the very beginning is for the convenience of myself. I have used awk for quite a few years. All my awk codes are very short and, naturally, each covers only a very limited subset of the language, which makes it impossible for me to remember even one-third of the essential but trivial elements of the language. So, each time I try to do something a little different, I have to turn to the manual for help. It's really boring. Now, all the built-in functions and variables on the menu, functioning as brief document, provide adequate help for me to start any code I might write. Indeed, the menu and its style seem to be not so compitable with those of Emacs. However, I guess lots of folks like me are happy to take the advantage of the easy accessible menu items. If there are some better way to deal with the small set of awk elements than that I dealt with, please let me know and I would like to change my code or just switch to yours. I'll contact Alan Mackenzie soon. Thanks a lot for your information and comments. David P.S., I pasted my awk-mode.el twice onto comp.emacs. I am afraid you might have got the first, so I am here having the newest code attached. If you have it, sorry for bothering. ----- Original Message ----- From: "Stefan Monnier" To: "Miles Bader" Cc: "Stefan Monnier" ; "Richard Stallman" ; ; ; ; "Alan Mackenzie" Sent: Tuesday, May 07, 2002 7:12 PM Subject: Re: new awk-mode > > > I'm confused. Is that the version that is intended to be cc-awk.el > > > (i.e. part of CC-mode) that someone was working on ? > > > > No. As far as I can see, it's the same as the `old' awk-mode, except > > with lots of menus added. > > > > Most of the menu entries seem to actually be `documentation,' where each > > menu entry label contains a short summary of a function or variable's > > usage, and selecting it inserts the summary as a sort of `template'. > > I hope it uses `define-skeleton' to define those templates. > > > I'm not entirely sure if the menus are the best place for all this info, > > but it might be handy (I'm forever browsing the manual whenever I write > > an awk program). > > > > There are other small changes too, but they _seem_ to actually be > > reversions, possibly because he based his code on an older copy of > > awk-mode.el than is in CVS (it's hard to tell because he sent the whole > > file instead of a patch). > > Then he should probably get in touch with Alan Mackenzie > so they can work together (Alan has been working on integrating awk-mode > into CC-mode to get an awk-specific indentation algorithm rather than > use the c-mode indentation which is all too often wrong). > > > Stefan > > ------=_NextPart_000_004D_01C1F610.D189E770 Content-Type: application/octet-stream; name="awk-mode.el" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="awk-mode.el" ;;; awk-mode.el --- AWK code editing commands for Emacs ;; Copyright (C) 1988,94,96,2000 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: unix, languages ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Sets up C-mode with support for awk-style #-comments and a lightly ;; hacked syntax table. ;;; Code: (defvar awk-mode-syntax-table nil "Syntax table in use in Awk-mode buffers.") (if awk-mode-syntax-table () (setq awk-mode-syntax-table (make-syntax-table)) (modify-syntax-entry ?\\ "\\" awk-mode-syntax-table) (modify-syntax-entry ?\n "> " awk-mode-syntax-table) (modify-syntax-entry ?\f "> " awk-mode-syntax-table) (modify-syntax-entry ?\# "< " awk-mode-syntax-table) (modify-syntax-entry ?/ "." awk-mode-syntax-table) (modify-syntax-entry ?* "." awk-mode-syntax-table) (modify-syntax-entry ?+ "." awk-mode-syntax-table) (modify-syntax-entry ?- "." awk-mode-syntax-table) (modify-syntax-entry ?=3D "." awk-mode-syntax-table) (modify-syntax-entry ?% "." awk-mode-syntax-table) (modify-syntax-entry ?< "." awk-mode-syntax-table) (modify-syntax-entry ?> "." awk-mode-syntax-table) (modify-syntax-entry ?& "." awk-mode-syntax-table) (modify-syntax-entry ?| "." awk-mode-syntax-table) (modify-syntax-entry ?_ "_" awk-mode-syntax-table) (modify-syntax-entry ?\' "\"" awk-mode-syntax-table)) ;; Regexps written with help from Peter Galbraith = . (defconst awk-font-lock-keywords (eval-when-compile (list ;; ;; Function names. '("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?" (1 font-lock-keyword-face) (2 font-lock-function-name-face nil = t)) ;; ;; Variable names. (cons (regexp-opt '("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RLENGTH" "RS" "RT" "RSTART" "SUBSEP") 'words) 'font-lock-variable-name-face) ;; ;; Keywords. (regexp-opt '("BEGIN" "END" "break" "continue" "delete" "do" "exit" "else" = "for" "getline" "if" "in" "next" "print" "printf" "return" "while") 'words) ;; ;; Builtins. (list (regexp-opt '("atan2" "close" "cos" "ctime" "exp" "fflush" "gensub" "gsub" = "index" "int" "length" "log" "match" "ord" "rand" "sin" "split" "sprintf" "sqrt" "srand" "strftime" "sub" "substr" "system" "systime" = "time" "tolower" "toupper") 'words) 1 'font-lock-builtin-face) ;; ;; Operators. Is this too much? (cons (regexp-opt '("&&" "||" "<=3D" "<" ">=3D" ">" "=3D=3D" "!=3D" = "!~" "~")) 'font-lock-constant-face) )) "Default expressions to highlight in AWK mode.") ;;; ;;; Awk menu by Zhongxiao (David) Wang, zwang@mail.smu.edu, on April 21, = 2002 ;;; ;;; Awk is, perhaps, the lightest programming language. However, = light-weight ;;; as it is, it's very gentle and powerful. Despite lots of popular = programming ;;; languages available, I take awk as a DAILY tool and like it the = best. In ;;; fact, it is its smallnest that makes it possible to add not so huge = a menu ;;; to provide almost all the essential parts of the language. Now, you = can take ;;; Emacs/Xemacs as an awk-specific integrated development environment = (IDE). ;;; ;;; Before you can enjoy the benefits this work can bring to you, you = might ;;; need to make sure that ;;; ;;; 1) GNU awk, gawk, has been installed in your system and its path is ;;; covered by the environment variable, PATH. ;;; ;;; If you have certain version of awk rather than gawk, please = rename it ;;; as gawk (in MS Windows, gawk.exe). ;;; ;;; 2) you had better have file, gawk.info. If you click Awk | Browse = Awk ;;; Manual with Info and no corresponding buffer appears, you need ;;; to set variable, Info-default-directory-list, in your = initialization ;;; file, .emacs, which is in your home directory, by adding = statement ;;; like ;;; =20 ;;; (setq Info-default-directory-list ;;; (cons "C:/cygwin/usr/info" Info-default-directory-list)) ;;; ;;; Special benefits for Windows users: ;;; ----------------------------------- ;;; You can obtain, through Internet, gawk.hlp, a Windows help file, = and ;;; put it right in your home directory. By doing so, you can start ;;; gawk.hlp within Emacs. (defvar awk-mode-map () "Keymap used in Awk mode.") (if awk-mode-map nil (setq awk-mode-map (make-sparse-keymap))) (defvar compilation-errors-p nil) (defvar awk-menu) (condition-case nil (progn (require 'easymenu) (require 'compile) (easy-menu-define awk-menu awk-mode-map "Menu for Awk mode" '("Awk" ["Run..." awk-run] ["Stop Running" kill-compilation] "---" ["Next Error" next-error compilation-errors-p] ["Previous Error" previous-error compilation-errors-p] ["First Error" first-error compilation-errors-p] "---" ["Awk Manual" awk-browse-info] "---" ["Frame of Function" awk-func-frame] ["Frame of Code" awk-code-frame] "---" ("Flow Control" ["if" (awk-if "if (")] ["if else" awk-ifelse] "---" ["for" (awk-if "for (; ;")] ["for (index in array)" (awk-if "for (index in array")] "---" ["while" (awk-if "while (")] ["do while" awk-dowhile] "---" ["break" (awk-text "break;")] ["continue" (awk-text "continue;")] ["exit" (awk-text "exit;")] ["exit expr" (awk-textbw "exit expr;" 1)] ["next" (awk-text "next;")] ["return" (awk-text "return;")] ["return expr" (awk-textbw "return expr;" 1)]) ("String Functions" ["gensub (reg, substr, how [, str]): string" (awk-textbw = "gensub(reg, substr, how [, str])" 4)] ["gsub (reg, substr [, str]): integer" (awk-textbw "gsub(reg, = substr [, str])" 3)] ["sub (reg, substr, str): integer" (awk-textbw "sub(reg, substr, = str)" 3)] "---" ["split (str, array [, reg])" (awk-textbw "split(str, array [, = reg]);" 3)] "---" ["index (str, substr): integer" (awk-textbw "index(str, substr)" = 2)] ["length (str): integer" (awk-textbw "length(str)" 1)] ["match (str, reg): integer" (awk-textbw "match(str, reg)" 2)] ["ord (str): integer (of str's 1st char)" (awk-textbw "ord(str)" = 1)] ["sprintf (format, expr-list): string" (awk-textbw "sprintf(format, = expr_list)" 3)] ["substr (str, start [, length]): string" (awk-textbw "substr(str, = start [, length])" 3)] "---" ["strftime (): string" (awk-text "strftime()")] ["strftime (format [, time-stamp]): string" (awk-textbw = "strftime(format [, time_stamp])" 3)] "---" ["tolower (str): string" (awk-textbw "tolower(str)" 1)] ["toupper (str): string" (awk-textbw "toupper(str)" 1)]) ("Input/Output" ["command | getline" (awk-textbw "\"command\" | getline;" 2)] ["getline" (awk-text "getline;")] ["getline < file" (awk-textbw "getline < file;" 1)] ["getline var" (awk-textbw "getline var;" 1)] ["getline var < file" (awk-textbw "getline var < file;" 2)] "---" ["print" (awk-text "print")] ["print > file" (awk-textbw "print > file;" 1)] ["printf format, expr-list" (awk-textbw "printf format, expr_list;" = 3)] ["printf format, expr-list > file" (awk-textbw "printf format, = expr_list > file;" 4)] "---" ["close (command)" (awk-textbw "close(command);" 1)] ["close (filename)" (awk-textbw "close(filename);" 1)] ["fflush ()" (awk-text "fflush();")] ["fflush (expr)" (awk-textbw "fflush(expr);" 1)] "---" ["/dev/stdin: standard input" (awk-text "\"/dev/stdin\"")] ["/dev/stdout: standard output" (awk-text "\"/dev/stdout\"")] ["/dev/stderr: standard error output" (awk-text = "\"/dev/stderr\"")]) ("System Interaction" ["command | getline" (awk-textbw "\"command\" | getline;" 2)] ["strftime (): See String Functions" (awk-text "strftime()")] ["system (command)" (awk-textbw "system(\"command\")" 1)] ["systime (): integer" (awk-text "systime()")]) ("Arithmetic Functions" ["int" (awk-func "int")] ["sin" (awk-func "sin")] ["cos" (awk-func "cos")] ["atan2" (awk-func "atan2")] ["sqrt" (awk-func "sqrt")] ["exp" (awk-func "exp")] ["log" (awk-func "log")] ["rand" (awk-func "rand")] ["srand" (awk-func "srand")]) ("Array Operation" ["delete array" (awk-textbw "delete array;" 1)] ["delete array [index]" (awk-textbw "delete array [index];" 2)] ["for (index in array) {...}" (awk-if "for (index in array")] ["split (string, array [, reg])" (awk-textbw "split(str, array [, = reg]);" 3)]) ("Built-in Variables" ["NF: number of fields in input line" (awk-text "NF")] ["FNR: input line number in current file" (awk-text "FNR")] ["NR: number of input lines read so far" (awk-text "NR")] "---" ["ARGC: number of command-line arguments" (awk-text "ARGC")] ["ARGIND: index in 'ARGV' of current file" (awk-text "ARGIND")] ["ARGV: array of command-line arguments (0..ARGC-1)" (awk-text = "ARGV")] "---" ["FS: input field separator (default: blank)" (awk-text "FS")] ["OFMT: output format for numbers (default: %.6g)" (awk-text = "OFMT")] ["OFS: output field separator (default: space)" (awk-text "OFS")] ["ORS: output line separator (default: newline)" (awk-text "ORS")] ["RS: input line separator (default: newline)" (awk-text "RS")] ["RT: input text matching text denoted by RS." (awk-text "RT")] ["SUBSEP: subscript separator (default: \\034)" (awk-text = "SUBSEP")] "---" ["RSTART: index of first character matched by match()" (awk-text = "RSTART")] ["RLENGTH: length of string matched by match()" (awk-text = "RLENGTH")] "---" ["CONVFMT: format to convert numbers to strings" (awk-text = "CONVFMT")] ["ENVIRON: associative array of environment variables" (awk-text = "ENVIRON")] ["ERRNO: error description string" (awk-text "ERRNO")] ["FILENAME: name of current input file" (awk-text "FILENAME")] ["IGNORECASE: case-independent matching" (awk-text "IGNORECASE")] "---" ["/dev/std*: See Input/Output" (awk-text "\"/dev/stdin\"")])))) (error nil)) ;;; ;;; implementation of menuitem functions ;;; ;;; If you put Windows help file, gawk.hlp, right in your home = directory, ;;; then, emacs will start it. Or, gawk.info will be used. (defun awk-browse-info() (interactive) (let ((gawkhlp (expand-file-name "~/gawk.hlp"))) (if (and (string-match "windows" (prin1-to-string system-type)) (file-exists-p gawkhlp)) (shell-command (concat "winhlp32.exe " gawkhlp)) (info "gawk.info"))) "Browse gawk manual with Info.") (defun awk-run() (interactive) (let ((command (concat "gawk -f \"" buffer-file-name "\""))) (if (buffer-modified-p) (save-buffer)) ;;; You can simply modify functions, compile-internal, = compilation-handle-exit and ;;; compilation-sentinel of compile.el, so as to have nicer result = window. However, ;;; it seems to be nonsense because you must maintain these = functions and have them ;;; compatible with the new versions of package compile. (compile-internal command "No more errors" "Running awk") (setq compilation-errors-p t)) "Call compile-internal of package compile to run awk script.") (defun awk-func-frame() (interactive) (insert = "\n###############################################################\n# = Input : \n# Output : \n# Description: = \n#\n###############################################################\n") (insert "function name(parameters, local_variables) {") (newline 2) (insert "}\n") (backward-word 4) "Insert frame of an awk function.") (defun awk-code-frame() (interactive) (insert = "###############################################################\n# = Script name: \n# Date: "); (insert (current-time-string)) (insert "\n# Author: David Wang, zwang@mail.smu.edu\n# Usage: = \n# Description: = \n#\n###############################################################") (insert "\nBEGIN {\n # set default values for any options & do = initialization\n\n # To run code in Emacs, you need to reset ARGC and = ARGV if you\n # are to process text files in the following way. = Besides, Awk\n # code must be in the same directory as those files, or = you need\n # to specify pathes of the latter.\n ARGV[1] =3D = \"mydata.dat\"; # take mydata.dat as the input text file\n ARGC =3D 2; = # previous index + 1\n}\n\nEND {\n # closing = code\n}\n\n# Active code in format: pattern { actions }\n{ print }\n") (previous-line 15) (c-indent-command) "Insert frame of awk code.") (defun awk-dowhile() (interactive) (insert "do {") (c-indent-command) (newline 2) (insert "} while ();") (c-indent-command) (newline) (previous-line 2) (c-indent-command) "Insert awk do-while structure.") (defun awk-ifelse() (interactive) (insert "if () {") (c-indent-command) (newline 2) (insert "} else {") (c-indent-command) (newline 2) (insert "}") (c-indent-command) (newline) (backward-word 2) (forward-word 1) (forward-char 2) "Insert awk if-else structure.") (defun awk-if(text) (interactive) (insert (concat text ") {")) (c-indent-command) (newline 2) (insert "}") (c-indent-command) (newline) (previous-line 3) (beginning-of-line) (forward-word 1) (forward-char 2) "Insert awk if/while/for structure.") (defun awk-text(text) (interactive) (insert text) "Insert awk simple text.") (defun awk-func(func) (interactive) (insert (concat func "()")) (backward-char) "Insert awk math function.") (defun awk-textbw(text n) (interactive) (insert text) (backward-word n) "Insert awk text and backward n words.") ;;; ;;; End of Awk menu by Zhongxiao (David) Wang, zwang@mail.smu.edu, on = April 21, 2002 ;;; ;;;###autoload (define-derived-mode awk-mode c-mode "AWK" "Major mode for editing AWK code. This is much like C mode except for the syntax of comments. Its keymap inherits from C mode's and it has the same variables for customizing indentation. It has its own abbrev table and its own syntax table. Turning on AWK mode runs `awk-mode-hook'." (set (make-local-variable 'paragraph-start) (concat "$\\|" = page-delimiter)) (set (make-local-variable 'paragraph-separate) paragraph-start) (set (make-local-variable 'comment-start) "# ") (set (make-local-variable 'comment-end) "") (set (make-local-variable 'comment-start-skip) "#+ *") (setq font-lock-defaults '(awk-font-lock-keywords nil nil ((?_ . = "w")))) ;;; David Wang (make-local-variable 'compilation-errors-p) (use-local-map awk-mode-map) (if (featurep 'easymenu) (easy-menu-add awk-menu)) ) (provide 'awk-mode) ;;; awk-mode.el ends here ------=_NextPart_000_004D_01C1F610.D189E770--