开发者

Making emacs to highlight postgresql syntax by default

开发者 https://www.devze.com 2023-02-06 10:04 出处:网络
I use emacs for editing my sql code. I work 99% of time on pos开发者_如何学运维tgresql plpgsql code. All my files with extension .sql contain postgresql. I\'m curious is there a way to set sql-highlig

I use emacs for editing my sql code. I work 99% of time on pos开发者_如何学运维tgresql plpgsql code. All my files with extension .sql contain postgresql. I'm curious is there a way to set sql-highlight-postgres-keywords SQL highlighting default instead of ANSI SQL, because it's pretty annoying to switch mode every time I open a file.


If you need to work with different databases, rather than using a hook to always switch to PostgreSQL highlighting when you open a .sql file, you can use Emacs' file variables feature to set the product on a file-by-file basis.

For example, if the first line of your .sql file is

-- -*- mode: sql; sql-product: postgres; -*-

sql-mode will automatically use PostgreSQL highlighting.

Full details on Emacs file variables here (you can also set them in a block anywhere in the file), and the list of product names is probably eaiest found by doing M-x sql-set-product, backspacing the ansi default, and hitting TAB to see the completion list. Examples are "mysql", "oracle", "sqlite", etc (about a dozen in my install).


Usually in emacs, if you want to change the settings every time some mode is opened, you use a hook. Something similar to this should work:

(add-to-list 'auto-mode-alist
             '("\\.psql$" . (lambda ()
                              (sql-mode)
                              (sql-highlight-postgres-keywords))))
0

精彩评论

暂无评论...
验证码 换一张
取 消