emacs-diffs
[Top][All Lists]
Advanced

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

master b39b564: * lisp/progmodes/sql.el: Try and avoid `eval`; use defin


From: Stefan Monnier
Subject: master b39b564: * lisp/progmodes/sql.el: Try and avoid `eval`; use define-derived-mode
Date: Sat, 14 Mar 2020 15:39:38 -0400 (EDT)

branch: master
commit b39b5647258297a411fae0adf58877bda85ad00d
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/progmodes/sql.el: Try and avoid `eval`; use define-derived-mode
    
    Remove redundant `:group` args.
    
    (sql-interactive-mode-map): `set-keymap-parent` is always fboundp.
    (sql-get-product-feature): Prefer `symbol-value` over `eval`.
    (sql--adjust-interactive-setup): New function, extracted from
    `sql-interactive-mode`.
    (sql-interactive-mode): Use it and `define-derived-mode`.
    (sql-connect, sql-connection-menu-filter): Prefer `cl-progv` over `eval`.
---
 lisp/progmodes/sql.el | 200 ++++++++++++++++++--------------------------------
 1 file changed, 70 insertions(+), 130 deletions(-)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 5eb8701..6fd750d 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -257,7 +257,6 @@
 (defcustom sql-user ""
   "Default username."
   :type 'string
-  :group 'SQL
   :safe 'stringp)
 
 (defcustom sql-password ""
@@ -265,33 +264,28 @@
 If you customize this, the value will be stored in your init
 file.  Since that is a plaintext file, this could be dangerous."
   :type 'string
-  :group 'SQL
   :risky t)
 
 (defcustom sql-database ""
   "Default database."
   :type 'string
-  :group 'SQL
   :safe 'stringp)
 
 (defcustom sql-server ""
   "Default server or host."
   :type 'string
-  :group 'SQL
   :safe 'stringp)
 
 (defcustom sql-port 0
   "Default port for connecting to a MySQL or Postgres server."
   :version "24.1"
   :type 'number
-  :group 'SQL
   :safe 'numberp)
 
 (defcustom sql-default-directory nil
   "Default directory for SQL processes."
   :version "25.1"
   :type '(choice (const nil) string)
-  :group 'SQL
   :safe 'stringp)
 
 ;; Login parameter type
@@ -707,9 +701,9 @@ making new SQLi sessions."
                  (repeat :inline t
                          (list :tab "Other"
                                (symbol :tag " Variable Symbol")
+                               ;; FIXME: Why "Value *Expression*"?
                                (sexp   :tag "Value Expression")))))
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 (defvaralias 'sql-dialect 'sql-product)
 
@@ -723,7 +717,6 @@ This allows highlighting buffers properly when you open 
them."
                                    (capitalize (symbol-name (car prod-info))))
                               ,(car prod-info)))
                     sql-product-alist))
-  :group 'SQL
   :safe 'symbolp)
 
 ;; SQL indent support
@@ -735,7 +728,6 @@ SQL statements with easy customizations to support varied 
layout
 requirements.
 
 The package must be available to be loaded and activated."
-  :group 'SQL
   :link '(url-link "https://elpa.gnu.org/packages/sql-indent.html";)
   :type 'boolean
   :version "27.1")
@@ -851,7 +843,6 @@ host key."
 See `sql-password-search-wallet-function' to understand how this value
 is used to locate the password wallet."
   :type `(plist-get (symbol-plist 'auth-sources) 'custom-type)
-  :group 'SQL
   :version "27.1")
 
 (defvar sql-password-search-wallet-function #'sql-auth-source-search-wallet
@@ -878,8 +869,7 @@ current input in the SQLi buffer to the process."
   :type '(choice (const :tag "Nothing" nil)
                 (const :tag "The semicolon `;'" semicolon)
                 (const :tag "The string `go' by itself" go))
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-send-terminator nil
   "When non-nil, add a terminator to text sent to the SQL interpreter.
@@ -907,8 +897,7 @@ it automatically."
                 (cons   :tag "Terminator Pattern and String"
                         (regexp :tag "Terminator Pattern")
                         (string :tag "Terminator String")))
-  :version "22.2"
-  :group 'SQL)
+  :version "22.2")
 
 (defvar sql-contains-names nil
   "When non-nil, the current buffer contains database names.
@@ -932,8 +921,7 @@ buffer."
   :type '(choice (const :tag "Default" t)
                  (const :tag "No display" nil)
                 (function :tag "Display Buffer function"))
-  :version "27.1"
-  :group 'SQL)
+  :version "27.1")
 
 ;; imenu support for sql-mode.
 
@@ -971,8 +959,7 @@ This is used to initialize `comint-input-ring-file-name'.
 Note that the size of the input history is determined by the variable
 `comint-input-ring-size'."
   :type '(choice (const :tag "none" nil)
-                (file))
-  :group 'SQL)
+                (file)))
 
 (defcustom sql-input-ring-separator "\n--\n"
   "Separator between commands in the history file.
@@ -987,21 +974,18 @@ does not have it, setting `sql-input-ring-separator' will 
have no
 effect.  In that case multiline commands will be split into several
 commands when the input history is read, as if you had set
 `sql-input-ring-separator' to \"\\n\"."
-  :type 'string
-  :group 'SQL)
+  :type 'string)
 
 ;; The usual hooks
 
 (defcustom sql-interactive-mode-hook '(sql-indent-enable)
   "Hook for customizing `sql-interactive-mode'."
   :type 'hook
-  :group 'SQL
   :version "27.1")
 
 (defcustom sql-mode-hook '(sql-indent-enable)
   "Hook for customizing `sql-mode'."
   :type 'hook
-  :group 'SQL
   :version "27.1")
 
 (defcustom sql-set-sqli-hook '()
@@ -1009,8 +993,7 @@ commands when the input history is read, as if you had set
 
 This is called by `sql-set-sqli-buffer' when the value of `sql-buffer'
 is changed."
-  :type 'hook
-  :group 'SQL)
+  :type 'hook)
 
 (defcustom sql-login-hook '()
   "Hook for interacting with a buffer in `sql-interactive-mode'.
@@ -1018,8 +1001,7 @@ is changed."
 This hook is invoked in a buffer once it is ready to accept input
 for the first time."
   :version "24.1"
-  :type 'hook
-  :group 'SQL)
+  :type 'hook)
 
 ;; Customization for ANSI
 
@@ -1033,8 +1015,7 @@ All products share this list; products should define a 
regexp to
 identify additional keywords in a variable defined by
 the :statement feature."
   :version "24.1"
-  :type 'regexp
-  :group 'SQL)
+  :type 'regexp)
 
 ;; Customization for Oracle
 
@@ -1046,27 +1027,23 @@ Starts `sql-interactive-mode' after doing some setup.
 On Windows, \"sqlplus\" usually starts the sqlplus \"GUI\".  In order
 to start the sqlplus console, use \"plus33\" or something similar.
 You will find the file in your Orant\\bin directory."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-oracle-options '("-L")
   "List of additional options for `sql-oracle-program'."
   :type '(repeat string)
-  :version "24.4"
-  :group 'SQL)
+  :version "24.4")
 
 (defcustom sql-oracle-login-params '(user password database)
   "List of login parameters needed to connect to Oracle."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 (defcustom sql-oracle-statement-starters
   (regexp-opt '("declare" "begin" "with"))
   "Additional statement starting keywords in Oracle."
   :version "24.1"
-  :type 'string
-  :group 'SQL)
+  :type 'string)
 
 (defcustom sql-oracle-scan-on t
   "Non-nil if placeholders should be replaced in Oracle SQLi.
@@ -1082,8 +1059,7 @@ You need to issue the following command in SQL*Plus to be 
safe:
 
 In older versions of SQL*Plus, this was the SET SCAN OFF command."
   :version "24.1"
-  :type 'boolean
-  :group 'SQL)
+  :type 'boolean)
 
 (defcustom sql-db2-escape-newlines nil
   "Non-nil if newlines should be escaped by a backslash in DB2 SQLi.
@@ -1092,8 +1068,7 @@ When non-nil, Emacs will automatically insert a space and
 backslash prior to every newline in multi-line SQL statements as
 they are submitted to an interactive DB2 session."
   :version "24.3"
-  :type 'boolean
-  :group 'SQL)
+  :type 'boolean)
 
 ;; Customization for SQLite
 
@@ -1103,21 +1078,18 @@ they are submitted to an interactive DB2 session."
   "Command to start SQLite.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-sqlite-options nil
   "List of additional options for `sql-sqlite-program'."
   :type '(repeat string)
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-sqlite-login-params '((database :file nil
                                                :must-match confirm))
   "List of login parameters needed to connect to SQLite."
   :type 'sql-login-params
-  :version "26.1"
-  :group 'SQL)
+  :version "26.1")
 
 ;; Customization for MariaDB
 
@@ -1134,22 +1106,19 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start mysql by Oracle.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-mysql-options nil
   "List of additional options for `sql-mysql-program'.
 The following list of options is reported to make things work
 on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
   :type '(repeat string)
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-mysql-login-params '(user password database server)
   "List of login parameters needed to connect to MySQL."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Solid
 
@@ -1157,14 +1126,12 @@ on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
   "Command to start SOLID SQL Editor.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-solid-login-params '(user password server)
   "List of login parameters needed to connect to Solid."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Sybase
 
@@ -1172,21 +1139,18 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start isql by Sybase.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-sybase-options nil
   "List of additional options for `sql-sybase-program'.
 Some versions of isql might require the -n option in order to work."
   :type '(repeat string)
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-sybase-login-params '(server user password database)
   "List of login parameters needed to connect to Sybase."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Informix
 
@@ -1194,14 +1158,12 @@ Some versions of isql might require the -n option in 
order to work."
   "Command to start dbaccess by Informix.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-informix-login-params '(database)
   "List of login parameters needed to connect to Informix."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Ingres
 
@@ -1209,14 +1171,12 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start sql by Ingres.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-ingres-login-params '(database)
   "List of login parameters needed to connect to Ingres."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Microsoft
 
@@ -1229,21 +1189,18 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start osql by Microsoft.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-ms-options '("-w" "300" "-n")
   ;; -w is the linesize
   "List of additional options for `sql-ms-program'."
   :type '(repeat string)
-  :version "22.1"
-  :group 'SQL)
+  :version "22.1")
 
 (defcustom sql-ms-login-params '(user password server database)
   "List of login parameters needed to connect to Microsoft."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Postgres
 
@@ -1251,8 +1208,7 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start psql by Postgres.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-postgres-options '("-P" "pager=off")
   "List of additional options for `sql-postgres-program'.
@@ -1263,8 +1219,7 @@ name, add the string \"-u\" to the list of options.  If 
you want to
 provide a user name on the command line (newer versions such as 7.1),
 add your name with a \"-U\" prefix (such as \"-Umark\") to the list."
   :type '(repeat string)
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-postgres-login-params
   `((user :default ,(user-login-name))
@@ -1275,8 +1230,7 @@ add your name with a \"-U\" prefix (such as \"-Umark\") 
to the list."
     server)
   "List of login parameters needed to connect to Postgres."
   :type 'sql-login-params
-  :version "26.1"
-  :group 'SQL)
+  :version "26.1")
 
 (defun sql-postgres-list-databases ()
   "Return a list of available PostgreSQL databases."
@@ -1297,20 +1251,17 @@ add your name with a \"-U\" prefix (such as \"-Umark\") 
to the list."
   "Command to start isql by Interbase.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-interbase-options nil
   "List of additional options for `sql-interbase-program'."
   :type '(repeat string)
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-interbase-login-params '(user password database)
   "List of login parameters needed to connect to Interbase."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for DB2
 
@@ -1318,20 +1269,17 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start db2 by IBM.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-db2-options nil
   "List of additional options for `sql-db2-program'."
   :type '(repeat string)
-  :version "20.8"
-  :group 'SQL)
+  :version "20.8")
 
 (defcustom sql-db2-login-params nil
   "List of login parameters needed to connect to DB2."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 ;; Customization for Linter
 
@@ -1339,20 +1287,17 @@ Starts `sql-interactive-mode' after doing some setup."
   "Command to start inl by RELEX.
 
 Starts `sql-interactive-mode' after doing some setup."
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-linter-options nil
   "List of additional options for `sql-linter-program'."
   :type '(repeat string)
-  :version "21.3"
-  :group 'SQL)
+  :version "21.3")
 
 (defcustom sql-linter-login-params '(user password database server)
   "Login parameters to needed to connect to Linter."
   :type 'sql-login-params
-  :version "24.1"
-  :group 'SQL)
+  :version "24.1")
 
 
 
@@ -1436,10 +1381,7 @@ specified, it's `sql-product' or `sql-connection' must 
match."
 
 (defvar sql-interactive-mode-map
   (let ((map (make-sparse-keymap)))
-    (if (fboundp 'set-keymap-parent)
-       (set-keymap-parent map comint-mode-map); Emacs
-      (if (fboundp 'set-keymap-parents)
-         (set-keymap-parents map (list comint-mode-map)))); XEmacs
+    (set-keymap-parent map comint-mode-map)
     (if (fboundp 'set-keymap-name)
        (set-keymap-name map 'sql-interactive-mode-map)); XEmacs
     (define-key map (kbd "C-j") 'sql-accumulate-and-indent)
@@ -2374,7 +2316,8 @@ function `regexp-opt'.")
 "ansi_warnings" "forceplan" "showplan_all" "showplan_text"
 "statistics" "implicit_transactions" "remote_proc_transactions"
 "transaction" "xact_abort"
-) t)
+)
+                   t)
        "\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$")
       'font-lock-doc-face)
 
@@ -2856,7 +2799,7 @@ See `sql-product-alist' for a list of products and 
supported features."
                (member feature sql-indirect-features)
                (not not-indirect)
                (symbolp v))
-              (eval v)
+              (symbol-value v)
             v))
       (error "`%s' is not a known product; use `sql-add-product' to add it 
first." product)
       nil)))
@@ -4245,7 +4188,6 @@ must tell Emacs.  Here's how to do that in your init file:
 \(add-hook \\='sql-mode-hook
           (lambda ()
            (modify-syntax-entry ?\\\\ \".\" sql-mode-syntax-table)))"
-  :group 'SQL
   :abbrev-table sql-mode-abbrev-table
 
   (if sql-mode-menu
@@ -4280,7 +4222,7 @@ must tell Emacs.  Here's how to do that in your init file:
 (put 'sql-interactive-mode 'mode-class 'special)
 (put 'sql-interactive-mode 'custom-mode-group 'SQL)
 ;; FIXME: Why not use `define-derived-mode'?
-(defun sql-interactive-mode ()
+(define-derived-mode sql-interactive-mode comint-mode "SQLi[?]"
   "Major mode to use a SQL interpreter interactively.
 
 Do not call this function by yourself.  The environment must be
@@ -4348,9 +4290,10 @@ you entered, right above the output it created.
 
 \(setq comint-output-filter-functions
        (function (lambda (STR) (comint-show-output))))"
+  :syntax-table sql-mode-syntax-table
   ;; FIXME: The doc above uses `setq' on `comint-output-filter-functions',
   ;; whereas hooks should be manipulated with things like `add/remove-hook'.
-  (delay-mode-hooks (comint-mode))
+  :after-hook (sql--adjust-interactive-setup)
 
   ;; Get the `sql-product' for this interactive session.
   (set (make-local-variable 'sql-product)
@@ -4358,14 +4301,11 @@ you entered, right above the output it created.
           sql-product))
 
   ;; Setup the mode.
-  (setq major-mode 'sql-interactive-mode)
   (setq mode-name
         (concat "SQLi[" (or (sql-get-product-feature sql-product :name)
                             (symbol-name sql-product)) "]"))
-  (use-local-map sql-interactive-mode-map)
   (if sql-interactive-mode-menu
       (easy-menu-add sql-interactive-mode-menu)) ; XEmacs
-  (set-syntax-table sql-mode-syntax-table)
 
   ;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
   ;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
@@ -4409,9 +4349,10 @@ you entered, right above the output it created.
   (add-hook 'comint-preoutput-filter-functions
             #'sql-interactive-remove-continuation-prompt nil t)
   (make-local-variable 'sql-input-ring-separator)
-  (make-local-variable 'sql-input-ring-file-name)
-  ;; Run the mode hook (along with comint's hooks).
-  (run-mode-hooks 'sql-interactive-mode-hook)
+  (make-local-variable 'sql-input-ring-file-name))
+
+(defun sql--adjust-interactive-setup ()
+  "Finish the mode's setup after running the mode hook."
   ;; Set comint based on user overrides.
   (setq comint-prompt-regexp
         (if sql-prompt-cont-regexp
@@ -4490,7 +4431,7 @@ is specified in the connection settings."
                 (dolist (vv connect-set)
                   (let ((var (car vv))
                         (val (cadr vv)))
-                    (set-default var (eval val))))
+                    (set-default var (eval val)))) ;FIXME: Why `eval'?
                 (setq-default sql-connection connection)
 
                 ;; :sqli-login params variable
@@ -4521,10 +4462,10 @@ is specified in the connection settings."
                                               (if vals (cons var vals) var)))))
 
                 ;; Start the SQLi session with revised list of login parameters
-                (eval `(let ((,param-var ',rem-vars))
-                         (sql-product-interactive
-                          ',sql-product
-                          ',(or buf-name (format "<%s>" connection))))))
+                (cl-progv (list param-var) (list rem-vars)
+                  (sql-product-interactive
+                   sql-product
+                   (or buf-name (format "<%s>" connection)))))
 
             (user-error "SQL Connection <%s> does not exist" connection)
             nil)))
@@ -4595,7 +4536,10 @@ optionally is saved to the user's init file."
          (format "Connection <%s>\t%s" (car conn)
                  (let ((sql-user "") (sql-database "")
                        (sql-server "") (sql-port 0))
-                   (eval `(let ,(cdr conn) (sql-make-alternate-buffer-name)))))
+                   (cl-progv
+                       (mapcar #'car (cdr conn))
+                       (mapcar #'cadr (cdr conn))
+                     (sql-make-alternate-buffer-name))))
          (list 'sql-connect (car conn))
          t))
     sql-connection-alist)
@@ -4977,8 +4921,7 @@ The default comes from `process-coding-system-alist' and
 
 See the distinct values in ALL_OBJECTS.OBJECT_TYPE for possible values."
   :version "24.1"
-  :type '(repeat string)
-  :group 'SQL)
+  :type '(repeat string))
 
 (defun sql-oracle-completion-object (sqlbuf schema)
   (sql-redirect-value
@@ -5624,21 +5567,18 @@ buffer.
 (defcustom sql-vertica-program "vsql"
   "Command to start the Vertica client."
   :version "25.1"
-  :type 'file
-  :group 'SQL)
+  :type 'file)
 
 (defcustom sql-vertica-options '("-P" "pager=off")
   "List of additional options for `sql-vertica-program'.
 The default value disables the internal pager."
   :version "25.1"
-  :type '(repeat string)
-  :group 'SQL)
+  :type '(repeat string))
 
 (defcustom sql-vertica-login-params '(user password database server)
   "List of login parameters needed to connect to Vertica."
   :version "25.1"
-  :type 'sql-login-params
-  :group 'SQL)
+  :type 'sql-login-params)
 
 (defun sql-comint-vertica (product options &optional buf-name)
   "Create comint buffer and connect to Vertica."



reply via email to

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