emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

linter support for sql.el


From: Alex Schroeder
Subject: linter support for sql.el
Date: Thu, 21 Nov 2002 00:14:14 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2.92 (i686-pc-linux-gnu)

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 <address@hidden>.
(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 <address@hidden>
  ;; Maintainer: Alex Schroeder <address@hidden>
! ;; 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 <address@hidden>
  ;; Maintainer: Alex Schroeder <address@hidden>
! ;; 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)
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]