alex-hhh / emacs-sql-indent

Syntax based indentation for SQL files inside GNU Emacs
GNU General Public License v3.0
121 stars 18 forks source link

SQL functions add a level of indentation to code below #54

Closed bopjesvla closed 6 years ago

bopjesvla commented 6 years ago

Current behavior:

create function a() returns int AS $$
  select 5
  $$;

  SELECT a();

Expected:

create function a() returns int AS $$
  select 5
$$;

SELECT a();
alex-hhh commented 6 years ago

Thanks for reporting this. Can you tell me what SQL dialect is this? Thanks, Alex.

bopjesvla commented 6 years ago

Thanks for the quick reply! Dollar-quoting of strings may be Postgres-specific, other than that it's all in the SQL standard.

alex-hhh commented 6 years ago

I added support for the $$ quote syntax in #55 with the following caveats:

(defvar my-sql-indentation-offsets-alist
  `((in-begin-block sqlind-use-anchor-indentation +)
    (block-end sqlind-use-anchor-indentation)
    ,@sqlind-default-indentation-offsets-alist))

(add-hook 'sqlind-minor-mode-hook
          (lambda ()
            (setq sqlind-indentation-offsets-alist
                  my-sql-indentation-offsets-alist)))

If you want to test the changes they are available in the pr54 branch if you clone this repo. Otherwise, I will merge the pull request in a day or so.

Best Regards, Alex.

alex-hhh commented 6 years ago

Merged the fix into the master branch, please let me know if you have any problems with it.