From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Alex Schroeder Newsgroups: gmane.emacs.devel Subject: linter support for sql.el Date: Thu, 21 Nov 2002 00:14:14 +0100 Sender: emacs-devel-admin@gnu.org Message-ID: <87bs4jq1fd.fsf_-_@emacswiki.org> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1037834215 27261 80.91.224.249 (20 Nov 2002 23:16:55 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 20 Nov 2002 23:16:55 +0000 (UTC) Cc: zheka@relex.ru Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18Ee5V-00075Z-00 for ; Thu, 21 Nov 2002 00:16:53 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18Ee8u-0002cQ-00 for ; Thu, 21 Nov 2002 00:20:24 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18Ee3z-0007XO-00; Wed, 20 Nov 2002 18:15:19 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18Ee39-0006vC-00 for emacs-devel@gnu.org; Wed, 20 Nov 2002 18:14:27 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18Ee31-0006qh-00 for emacs-devel@gnu.org; Wed, 20 Nov 2002 18:14:26 -0500 Original-Received: from isp247n.hispeed.ch ([62.2.95.247] helo=smtp.hispeed.ch) by monty-python.gnu.org with esmtp (Exim 4.10) id 18Ee2z-0006jd-00 for emacs-devel@gnu.org; Wed, 20 Nov 2002 18:14:18 -0500 Original-Received: from confusibombus (dclient217-162-232-121.hispeed.ch [217.162.232.121]) by smtp.hispeed.ch (8.12.6/8.12.6/tornado-1.0) with ESMTP id gAKNEErg009484; Thu, 21 Nov 2002 00:14:14 +0100 Original-Received: from alex by confusibombus with local (Exim 3.35 #1 (Debian)) id 18Ee2w-0000C4-00; Thu, 21 Nov 2002 00:14:14 +0100 Original-To: emacs-devel@gnu.org X-Face: ^BC$`[IcggstLPyen&dqF+b2'zyK#r.mU*'Nms}@&4zw%SJ#5!/7SMVjBS7'lb;QK)|IPU5U'o1'522W4TyzB3Ab*IBo^iw]l4|kUbdZuUDO6=Um-.4IzhNiV'B"@K#jy_(wW|Zbk[34flKY^|PrQ?$u2\fKg^]AY>wOX#H32i In-Reply-To: (Richard Stallman's message of "Wed, 20 Nov 2002 16:13:18 -0500") Original-Lines: 334 User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2.92 (i686-pc-linux-gnu) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:9585 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:9585 Can somebody commit this patch to sql.el for me? Eugene Exarevsky has sent papers, and RMS has checked it. :) Thanks, Alex. ChangeLog: Added LINTER support by Eugene Exarevsky . (sql-linter-program): New variable. (sql-linter-options): New variable. (sql-mode-menu): Added Linter keywords. (sql-mode-linter-font-lock-keywords): New variable. (sql-highlight-linter-keywords): New function. (sql-linter): New function. (sql-ms-options): New variable. (sql-ms): Use it. *** sql.el.~1.32.~ Thu Nov 21 00:09:34 2002 --- sql.el Thu Nov 21 00:12:50 2002 *************** *** 1,10 **** ;;; sql.el --- specialized comint.el for SQL interpreters ! ;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. ;; Author: Alex Schroeder ;; Maintainer: Alex Schroeder ! ;; Version: 1.6.5 ;; Keywords: comm languages processes ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode --- 1,10 ---- ;;; sql.el --- specialized comint.el for SQL interpreters ! ;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. ;; Author: Alex Schroeder ;; Maintainer: Alex Schroeder ! ;; Version: 1.7.0 ;; Keywords: comm languages processes ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode *************** *** 343,348 **** --- 343,355 ---- :type 'file :group 'SQL) + (defcustom sql-ms-options '("-w" "300" "-n") + ;; -w is the linesize + "*List of additional options for `sql-ms-program'." + :type '(repeat string) + :version "21.4" + :group 'SQL) + ;; Customization for Postgres (defcustom sql-postgres-program "psql" *************** *** 400,405 **** --- 407,427 ---- :version "20.8" :group 'SQL) + ;; Customization for Linter + + (defcustom sql-linter-program "inl" + "*Command to start inl by RELEX. + + Starts `sql-interactive-mode' after doing some setup." + :type 'file + :group 'SQL) + + (defcustom sql-linter-options nil + "*List of additional options for `sql-linter-program'." + :type '(repeat string) + :version "21.3" + :group 'SQL) + ;;; Variables which do not need customization *************** *** 491,497 **** ("Highlighting" ["ANSI SQL keywords" sql-highlight-ansi-keywords t] ["Oracle keywords" sql-highlight-oracle-keywords t] ! ["Postgres keywords" sql-highlight-postgres-keywords t]))) ;; easy menu for sql-interactive-mode. --- 513,521 ---- ("Highlighting" ["ANSI SQL keywords" sql-highlight-ansi-keywords t] ["Oracle keywords" sql-highlight-oracle-keywords t] ! ["Postgres keywords" sql-highlight-postgres-keywords t] ! ["Linter keywords" sql-highlight-linter-keywords t] ! ))) ;; easy menu for sql-interactive-mode. *************** *** 713,718 **** --- 737,836 ---- (cons postgres-types 'font-lock-type-face)))))) + (defvar sql-mode-linter-font-lock-keywords nil + "Linter SQL keywords used by font-lock. + + This variable is used by `sql-mode' and `sql-interactive-mode'. The + regular expressions are created during compilation by calling the + function `regexp-opt'.") + + (if sql-mode-linter-font-lock-keywords + () + (let ((linter-keywords (eval-when-compile + (concat "\\b" + (regexp-opt '( + "autocommit" "autoinc" "autorowid" "cancel" "cascade" "channel" + "committed" "count" "countblob" "cross" "current" "data" "database" + "datafile" "datafiles" "datesplit" "dba" "dbname" "default" "deferred" + "denied" "description" "device" "difference" "directory" "error" + "escape" "euc" "exclusive" "external" "extfile" "false" "file" + "filename" "filesize" "filetime" "filter" "findblob" "first" "foreign" + "full" "fuzzy" "global" "granted" "ignore" "immediate" "increment" + "indexes" "indexfile" "indexfiles" "indextime" "initial" "integrity" + "internal" "key" "last_autoinc" "last_rowid" "limit" "linter" + "linter_file_device" "linter_file_size" "linter_name_length" "ln" + "local" "login" "maxisn" "maxrow" "maxrowid" "maxvalue" "message" + "minvalue" "module" "names" "national" "natural" "new" "new_table" + "no" "node" "noneuc" "nulliferror" "numbers" "off" "old" "old_table" + "only" "operation" "optimistic" "option" "page" "partially" "password" + "phrase" "plan" "precision" "primary" "priority" "privileges" + "proc_info_size" "proc_par_name_len" "protocol" "quant" "range" "raw" + "read" "record" "records" "references" "remote" "rename" "replication" + "restart" "rewrite" "root" "row" "rule" "savepoint" "security" + "sensitive" "sequence" "serializable" "server" "since" "size" "some" + "startup" "statement" "station" "success" "sys_guid" "tables" "test" + "timeout" "trace" "transaction" "translation" "trigger" + "trigger_info_size" "true" "trunc" "uncommitted" "unicode" "unknown" + "unlimited" "unlisted" "user" "utf8" "value" "varying" "volumes" + "wait" "windows_code" "workspace" "write" "xml" + ) t) "\\b"))) + (linter-reserved-words (eval-when-compile + (concat "\\b" + (regexp-opt '( + "access" "action" "add" "address" "after" "all" "alter" "always" "and" + "any" "append" "as" "asc" "ascic" "async" "at_begin" "at_end" "audit" + "aud_obj_name_len" "backup" "base" "before" "between" "blobfile" + "blobfiles" "blobpct" "brief" "browse" "by" "case" "cast" "check" + "clear" "close" "column" "comment" "commit" "connect" "contains" + "correct" "create" "delete" "desc" "disable" "disconnect" "distinct" + "drop" "each" "ef" "else" "enable" "end" "event" "except" "exclude" + "execute" "exists" "extract" "fetch" "finish" "for" "from" "get" + "grant" "group" "having" "identified" "in" "index" "inner" "insert" + "instead" "intersect" "into" "is" "isolation" "join" "left" "level" + "like" "lock" "mode" "modify" "not" "nowait" "null" "of" "on" "open" + "or" "order" "outer" "owner" "press" "prior" "procedure" "public" + "purge" "rebuild" "resource" "restrict" "revoke" "right" "role" + "rollback" "rownum" "select" "session" "set" "share" "shutdown" + "start" "stop" "sync" "synchronize" "synonym" "sysdate" "table" "then" + "to" "union" "unique" "unlock" "until" "update" "using" "values" + "view" "when" "where" "with" "without" + ) t) "\\b"))) + (linter-types (eval-when-compile + (concat "\\b" + (regexp-opt '( + "bigint" "bitmap" "blob" "boolean" "char" "character" "date" + "datetime" "dec" "decimal" "double" "float" "int" "integer" "nchar" + "number" "numeric" "real" "smallint" "varbyte" "varchar" "byte" + "cursor" "long" + ) t) "\\b"))) + (linter-builtin-functions (eval-when-compile + (concat "\\b" + (regexp-opt '( + "abs" "acos" "asin" "atan" "atan2" "avg" "ceil" "cos" "cosh" "divtime" + "exp" "floor" "getbits" "getblob" "getbyte" "getlong" "getraw" + "getstr" "gettext" "getword" "hextoraw" "lenblob" "length" "log" + "lower" "lpad" "ltrim" "max" "min" "mod" "monthname" "nvl" + "octet_length" "power" "rand" "rawtohex" "repeat_string" + "right_substr" "round" "rpad" "rtrim" "sign" "sin" "sinh" "soundex" + "sqrt" "sum" "tan" "tanh" "timeint_to_days" "to_char" "to_date" + "to_gmtime" "to_localtime" "to_number" "trim" "upper" "decode" + "substr" "substring" "chr" "dayname" "days" "greatest" "hex" "initcap" + "instr" "least" "multime" "replace" "width" + ) t) "\\b")))) + (setq sql-mode-linter-font-lock-keywords + (append sql-mode-ansi-font-lock-keywords + (list (cons linter-keywords 'font-lock-function-name-face) + (cons linter-reserved-words 'font-lock-keyword-face) + ;; XEmacs doesn't have font-lock-builtin-face + (if (string-match "XEmacs\\|Lucid" emacs-version) + (cons linter-builtin-functions 'font-lock-preprocessor-face) + ;; GNU Emacs 19 doesn't have it either + (if (string-match "GNU Emacs 19" emacs-version) + (cons linter-builtin-functions 'font-lock-function-name-face) + ;; Emacs + (cons linter-builtin-functions 'font-lock-builtin-face))) + (cons linter-types 'font-lock-type-face)))))) + (defvar sql-mode-font-lock-keywords sql-mode-ansi-font-lock-keywords "SQL keywords used by font-lock. *************** *** 738,743 **** --- 856,868 ---- (setq font-lock-keywords sql-mode-postgres-font-lock-keywords) (font-lock-fontify-buffer)) + (defun sql-highlight-linter-keywords () + "Highlight LINTER keywords. + Basically, this just sets `font-lock-keywords' appropriately." + (interactive) + (setq font-lock-keywords sql-mode-linter-font-lock-keywords) + (font-lock-fontify-buffer)) + (defun sql-highlight-ansi-keywords () "Highlight ANSI SQL keywords. Basically, this just sets `font-lock-keywords' appropriately." *************** *** 809,814 **** --- 934,940 ---- Ingres: \\[sql-ingres] Microsoft: \\[sql-ms] Interbase: \\[sql-interbase] + Linter: \\[sql-linter] But we urge you to choose a free implementation instead of these. *************** *** 1612,1618 **** Interpreter used comes from variable `sql-ms-program'. Login uses the variables `sql-user', `sql-password', `sql-database', and `sql-server' ! as defaults, if set. The buffer is put in sql-interactive-mode, giving commands for sending input. See `sql-interactive-mode'. --- 1738,1745 ---- Interpreter used comes from variable `sql-ms-program'. Login uses the variables `sql-user', `sql-password', `sql-database', and `sql-server' ! as defaults, if set. Additional command line parameters can be stored ! in the list `sql-ms-options'. The buffer is put in sql-interactive-mode, giving commands for sending input. See `sql-interactive-mode'. *************** *** 1632,1638 **** (message "Login...") ;; Put all parameters to the program (if defined) in a list and call ;; make-comint. ! (let ((params '("-w 300"))) (if (not (string= "" sql-server)) (setq params (append (list "-S" sql-server) params))) (if (not (string= "" sql-database)) --- 1759,1765 ---- (message "Login...") ;; Put all parameters to the program (if defined) in a list and call ;; make-comint. ! (let ((params sql-ms-options)) (if (not (string= "" sql-server)) (setq params (append (list "-S" sql-server) params))) (if (not (string= "" sql-database)) *************** *** 1808,1813 **** --- 1935,1996 ---- (setq comint-input-sender 'sql-escape-newlines-and-send) (message "Login...done") (pop-to-buffer sql-buffer))) + + ;;;###autoload + (defun sql-linter () + "Run inl by RELEX as an inferior process. + + If buffer `*SQL*' exists but no process is running, make a new process. + If buffer exists and a process is running, just switch to buffer + `*SQL*'. + + Interpreter used comes from variable `sql-linter-program' - usually `inl'. + Login uses the variables `sql-user', `sql-password', `sql-database' and + `sql-server' as defaults, if set. Additional command line parameters + can be stored in the list `sql-linter-options'. Run inl -h to get help on + parameters. + + `sql-database' is used to set the LINTER_MBX environment variable for + local connections, `sql-server' refers to the server name from the + `nodetab' file for the network connection (dbc_tcp or friends must run + for this to work). If `sql-password' is an empty string, inl will use + an empty password. + + The buffer is put in sql-interactive-mode, giving commands for sending + input. See `sql-interactive-mode'. + + To use LINTER font locking by default, put this line into your .emacs : + (setq sql-mode-font-lock-keywords sql-mode-linter-font-lock-keywords) + + \(Type \\[describe-mode] in the SQL buffer for a list of commands.)" + (interactive) + (if (comint-check-proc "*SQL*") + (pop-to-buffer "*SQL*") + (sql-get-login 'user 'password 'database 'server) + (message "Login...") + ;; Put all parameters to the program (if defined) in a list and call + ;; make-comint. + (let ((params sql-linter-options) (login nil) (old-mbx (getenv "LINTER_MBX"))) + (if (not (string= "" sql-user)) + (setq login (concat sql-user "/" sql-password))) + (setq params (append (list "-u" login) params)) + (if (not (string= "" sql-server)) + (setq params (append (list "-n" sql-server) params))) + (if (string= "" sql-database) + (setenv "LINTER_MBX" nil) + (setenv "LINTER_MBX" sql-database)) + (set-buffer (apply 'make-comint "SQL" sql-linter-program nil + params)) + (setenv "LINTER_MBX" old-mbx) + ) + (setq sql-prompt-regexp "^SQL>") + (setq sql-prompt-length 4) + (setq sql-buffer (current-buffer)) + (sql-interactive-mode) + (message "Login...done") + (pop-to-buffer sql-buffer))) + + (provide 'sql)