Coder Social home page Coder Social logo

Comments (14)

PierreTechoueyres avatar PierreTechoueyres commented on September 28, 2024

Only for that block ? I don't know !
But if you enable sqlind-minor-mode for buffers with sql-mode then I think you could achieve that. You could do that using the sql-mode-hook with something (untested) like bellow:

(add-hook 'sql-mode-hook '(lambda () (sqlind-minor-mode 1)))

But If you're using emacs 27.1 and have installed this package then it should already be enabled ...

from emacs-sql-indent.

alex-hhh avatar alex-hhh commented on September 28, 2024

I am not using source blocks in org mode, but a quick check, indentation does not seem to work with the C or Pyhton languages either. So perhaps, this is not supported in org-mode?

I would suggest you ask this questions in org-mode discussion lists for help about this.

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

Thanks for the support!

I was enabling the minor mode in the sql-mode-hook already 🙂

(use-package! sql-indent
  :hook ((sql-mode-hook . sqlind-minor-mode)))

@alex-hhh You're probably right, but can you please check if you have these settings:

org-src-tab-acts-natively     t
org-src-preserve-indentation  t
org-src-fontify-natively      t

Supposedly that allows langs to dictate the indentation which I'd like to confirm to make sure it's an org issue and not more isolated.

from emacs-sql-indent.

alex-hhh avatar alex-hhh commented on September 28, 2024

You are correct, I did not have these settings (I told you I don't use that feature in org mode). However, if I enable them, the SQL mode indentation now works (along with the indentation for C and Python blocks). I didn't do anything special with my setup, it just worked once I enabled the org mode features.

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

Thanks for looking into it! The fact that it's working for you means this is likely a problem I caused in my config.

I'm pretty intermediate with emacs but I won't waste your time with too much backstory, I was inspired by https://youtu.be/dljNabciEGg to get more out of org-mode. I have to go through 300 tables to truncate\prune what I can for a lighter development DB import. Being able to document each table's purpose and record the queries for inspection\truncating that are executable from within the org-mode src block has proven an extremely pleasant approach so far.

from emacs-sql-indent.

alex-hhh avatar alex-hhh commented on September 28, 2024

Hi @eccentric-j if you ended up fixing the problem, can you please add a comment to this issue of what the problem and fix were? In case other people have similar problems and search the issue tracker. Thanks, Alex.

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

Unfortunately no such luck. I'm back to square one. Python is working, but unfortunately not SQL:

2020-08-19 22 18 16

Trying to think through where to even look, considering possibilities:

  1. I'm still not configuring sql-indent correctly even though it works in SQL buffers including using C-' in SQL src blocks. Seems like the most plausible yet there's only 1 line config required which I've included my current config in the gif
  2. Doom emacs is adding config that is causing indent to behave differently. This doesn't seem likely either given that Python's indent is working, but on the other hand, SQL was working for you once you enabled those core src block formatting settings.
  3. A SQL indent issue. Seems even less likely than the other two possibilities given that it was indenting correctly for you in SQL src blocks.
  4. An org-mode issue. Seems slightly possible, but it seems Python and JS indent correctly for me.

Where would you (or anyone here) start?

from emacs-sql-indent.

alex-hhh avatar alex-hhh commented on September 28, 2024

You can use the following steps to check if there is an interference from another package or configuration setting:

  • start emacs using emacs -Q --no-site-file -- this will start Emacs without loading any configuration files
  • Start an IELM buffer (type M-x ielm RET and type in the following:
(require 'sql-indent)
(add-hook 'sql-mode-hook 'sqlind-minor-mode)
(setq org-src-tab-acts-natively  t)
(setq org-src-preserve-indentation t)
(setq org-src-fontify-natively t)

and try to see if this is working, if it does, the problem is somewhere in your configuration or other loaded packages.

Also, if the (require 'sql-indent) fails, you will need to update the load path using:

(setq load-path (cons "PATH-TO-SQL-INDENT-PACKAGE-HERE" load-path)

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

Found the cause:

Doom has added advice to the editing of src blocks that prevents major mode hooks from firing which is why sqlind-minor-mode is not seemingly activating while editing src blocks.

My temporary solution:

(after! org
  (advice-remove #'org-src--edit-element #'+org-inhibit-mode-hooks-a))

But may degrade performance. Created a bug ticket, awaiting a better solution strategy. Thanks again for your help, it really helped me dig my way through.

from emacs-sql-indent.

alex-hhh avatar alex-hhh commented on September 28, 2024

This was a good investigation! The reason why C, JS and Python work is because their indentation is provided by the default package (c-mode, js-mode or python-mode). for SQL indentation is not provided by sql-mode, but by this separate package, which needs to be activated when SQL mode is enabled for a buffer.

As for why this is a separate package, it is a long story (#5).

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

This was a good investigation! The reason why C, JS and Python work is because their indentation is provided by the default package (c-mode, js-mode or python-mode). for SQL indentation is not provided by sql-mode, but by this separate package, which needs to be activated when SQL mode is enabled for a buffer.

That's exactly what I was leaning towards as well.

As for why this is a separate package, it is a long story (#5).

Oof that's really too bad it all comes down to 1 person not liking it.

What options are available to address it given that it can't be merged upstream?

from emacs-sql-indent.

alex-hhh avatar alex-hhh commented on September 28, 2024

That one person is the sql mode maintainer, so his opinion carries a lot of weight :-). In any case, sql-indent has been available as a package from ELPA for a while now, and will remain like this for the foreseeable future.

from emacs-sql-indent.

jaidetree avatar jaidetree commented on September 28, 2024

That's fair. I have no idea when it makes sense to have an informed maintainer making less-popular but potentially more sustainable decisions vs democratized project.

Anyway for anyone coming to this later the maintainer of Doom released an update with a fix doomemacs/doomemacs@dddfd9a.

from emacs-sql-indent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.