Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggressive-indent-mode incompatibility #30

Open
walseb opened this issue Jan 7, 2019 · 14 comments
Open

Aggressive-indent-mode incompatibility #30

walseb opened this issue Jan 7, 2019 · 14 comments

Comments

@walseb
Copy link

walseb commented Jan 7, 2019

When typing a bit after enabling both aggressive-indent-mode and emacs-ccls, the text above and below where you are typing will get deleted. The problem is present with this minimal config

;; Bootstrap straight.el for package management
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'aggressive-indent)
(global-aggressive-indent-mode)

(straight-use-package 'lsp-mode)

(straight-use-package 'ccls)
(require 'ccls)
(setq ccls-executable "/bin/ccls")

(add-hook 'c-mode-hook 'lsp)
(add-hook 'c++-mode-hook 'lsp)
(add-hook 'objc-mode-hook 'lsp)
@walseb walseb changed the title Aggressive indent mode compatibility Aggressive-indent-mode incompatibility Jan 7, 2019
@innerout
Copy link

If you use this

(add-to-list
 'aggressive-indent-dont-indent-if
 '(and (derived-mode-p 'c++-mode)
       (null (string-match "\\([;{}]\\|\\b\\(if\\|for\\|while\\)\\b\\)"
                           (thing-at-point 'line)))))

Does it still happen?

@walseb
Copy link
Author

walseb commented Mar 14, 2019

The problem isn't there anymore but aggressive-indent-mode doesn't do anything either. Even if my buffer doesn't match the regex (which is hard to create because it looks like it will match anything that has parens, ifs, etc).

@innerout
Copy link

It works fine for me. Are you sure that the problem is not something else?

@walseb
Copy link
Author

walseb commented Mar 15, 2019

I just tried my minimal config above together with your suggestion and the problem is still there (text is still deleted). I think I forgot to enable aggresive-indent in my last reply. I used this c++ sample file

#include <stdio.h>
int main()
{
    int i, j, rows;

    printf("Enter number of rows: ");
    scanf("%d",&rows);

    for(i=1; i<=rows; ++i)
    {
	for(j=1; j<=i; ++j)
	{
	    printf("* ");
	}
	printf("\n");
    }
    return 0;
}

@innerout
Copy link

innerout commented Mar 16, 2019

What emacs version are you running ?Also can you check if company is activated before or after aggressive-indent ?

@walseb
Copy link
Author

walseb commented Mar 16, 2019

I'm running the latest stable arch linux build of emacs: GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2018-07-05
The minimal config in op didn't have company installed, but i tried adding

(straight-use-package 'company)
(global-company-mode)

to it with the same results as my last post

@innerout
Copy link

Instead of

(global-aggressive-indent-mode)

can you try hooking up aggressive-indent-mode on c-mode-hook and c++-mode-hook?

@walseb
Copy link
Author

walseb commented Mar 17, 2019

That seems to make it more stable, but text is still randomly deleted if you press delete in this situation

    code
   |int var = 10;
    code

| = cursor

@innerout
Copy link

OK at least we improved something, another concern i have is that Maskray has configured ccls in wiki using 3 different hooks from you.

  :hook ((c-mode c++-mode objc-mode) .
         (lambda () (require 'ccls) (lsp)))

Can you remove from your config

(add-hook 'c-mode-hook 'lsp)
(add-hook 'c++-mode-hook 'lsp)
(add-hook 'objc-mode-hook 'lsp)

and replace it with the equivalent code of straight.el-use-package based on the code i mentioned above?

@walseb
Copy link
Author

walseb commented Mar 17, 2019

That's the same as

(add-hook 'c-mode-hook '(lambda () (require 'ccls) (lsp)))
(add-hook 'c++-mode-hook '(lambda () (require 'ccls) (lsp)))
(add-hook 'objc-mode-hook '(lambda () (require 'ccls) (lsp)))

which has the same problem

@innerout
Copy link

I am not sure but c-mode and c-mode-hook are not the same.
The equivalent to what i said is.

(add-hook 'c-mode '(lambda () (require 'ccls) (lsp)))
(add-hook 'c++-mode '(lambda () (require 'ccls) (lsp)))
(add-hook 'objc-mode '(lambda () (require 'ccls) (lsp)))

@walseb
Copy link
Author

walseb commented Mar 17, 2019

No, every mode has a hook that is run when it is enabled, so what :hook ((c-mode c++-mode objc-mode) . does is that it takes the hooks of those modes and runs whatever is after the dot when those hooks are run
What's written after (add-hook 'c-mode never executes because c-mode is just a function that inits the c-mode, not a hook

@0x00539
Copy link

0x00539 commented Jun 9, 2019

(setq lsp-enable-indentation nil)
(setq lsp-enable-on-type-formatting nil)
seemed to fix it for me

@innerout
Copy link

I can confirm the solution proposed from @0x00539 works.

seagle0128 added a commit to seagle0128/.emacs.d that referenced this issue Feb 18, 2020
See emacs-lsp/emacs-ccls#30.

1. Disable lsp-enable-indent.
2. Disable lsp-enable-on-type-formatting.
seagle0128 added a commit to seagle0128/.emacs.d that referenced this issue Feb 18, 2020
Close #161.
See emacs-lsp/emacs-ccls#30.

1. Disable lsp-enable-indent.
2. Disable lsp-enable-on-type-formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants