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

Undesired newline insertion when jumping to a Recent Files item from *spacemacs* Home buffer #13671

Closed
fperies opened this issue Jun 12, 2020 · 14 comments

Comments

@fperies
Copy link
Contributor

fperies commented Jun 12, 2020

Description :octocat:

Undesired run of 'newline-and-indent' command when clicking on a Recent Files item from spacemacs Home buffer

Reproduction guide 🪲

  • Start Emacs
    Simply click on a Recent Files item which is not in Read-Only mode

Observed behaviour: 👀 💔
You get a spurious newline insertion

Expected behaviour: ❤️ 😄
No spurious newline insertion

System Info 💻

  • OS: gnu/linux
  • Emacs: 26.1
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 2bc80b4)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: emacs
  • Completion: helm
  • Layers:
(asciidoc
 (auto-completion :variables auto-completion-use-company-box t)
 (c-c++ :variables c-c++-default-mode-for-headers 'c++-mode)
 (c-c++ :variables c-c++-enable-clang-format-on-save t)
 (c-c++ :variables c-c++-backend 'rtags)
 cmake csv fzf emacs-lisp git helm html imenu-list javascript lsp lua markdown org
 (plantuml :variables plantuml-jar-path "~/plantuml.jar")
 python treemacs syntax-checking themes-megapack)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND DBUS GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 MODULES THREADS

Backtrace 🐾


UPDATE:
I've just noticed this issue is not present when pressing RET key or C-m shortkey.
The undesired newline comes in when clicking with mouse-1 button on one recent file link.
So the entry point should be widget-button-click function.

@emacs18
Copy link
Contributor

emacs18 commented Jun 15, 2020

You can setup to have stack trace printed when newline-and-indent function is executed by evaluating this expression:

(debug-on-entry 'newline-and-indent)

You can either add this line somewhere in your startup file or type in the line after emacs starts by hitting M-: then typing the line above. Now you can click on the recent files. If newline-and-indent is called, then a stack trace should be printed. If you report back that stack trace, then that could be important in figuring this out.

@fperies
Copy link
Contributor Author

fperies commented Jun 15, 2020

@emacs18 , thank you for your reply.

I've already tried your suggestion but I'm afraid it will not provide any useful additional information.
See backtrace below:

Debugger entered--entering a function:
* newline-and-indent()
  funcall-interactively(newline-and-indent)
  call-interactively(newline-and-indent nil nil)
  command-execute(newline-and-indent)

Let me know if you have an other suggestions.

Thanks

@emacs18
Copy link
Contributor

emacs18 commented Jun 15, 2020

The stack trace seems to indicate that newline-and-indent was called explicitly by calling it interactively! Pehaps I did not understand the problem replication procedure. I thought that you ran into this problem merely by (a) starting spacemacs, and (b) clicking on one of the recent files link shown on the initial buffer named *spacemacs*. Is this not the case?

@fperies
Copy link
Contributor Author

fperies commented Jun 15, 2020

Yes this is exactly the scenario.
But please see UPDATE above:
"I've just noticed this issue is not present when pressing RET key or C-m shortkey.
The undesired newline comes in when clicking with mouse-1 button on one recent file link.
So the entry point should be widget-button-click function."

The strange thing is that if I do a "long" click on a recent file, the face goes red, the buffer is switched and there is no undesired newline.
If I do a "short" click, the buffer is switched and an undesired newline is inserted.
It seems to me something is not correctly managed in the widget-button-click function.

@emacs18
Copy link
Contributor

emacs18 commented Jun 15, 2020

Can you share the major mode of the buffer where this problem occurs?

@fperies
Copy link
Contributor Author

fperies commented Jun 15, 2020

I've noticed the issue with C/C++ and also JSON major modes

@emacs18
Copy link
Contributor

emacs18 commented Jun 15, 2020

In my C++ buffer only RET key is bound to newline-and-indent command. So the only way for me to execute this command interactively is to hit RET key. I'm not sure if it is possible for me to execute this command via mouse clicks. I'm not sure what else I can suggest other than peeling away your own custom stuff and go back to as vanilla spacemacs as possible. Sorry.

@fperies
Copy link
Contributor Author

fperies commented Jun 15, 2020

The key binding is relevant for spacemacs buffer.
What happens if you quickly click on your C++ buffer from spacemacs buffer link ?
Do you observe a newline inserted ?

@emacs18
Copy link
Contributor

emacs18 commented Jun 15, 2020

No. I am unable to reproduce the problem no matter what I try.

In my *spacemacs* buffer, newline-and-indent is not bound to any key. The reason for my previous comment is, because it is more likely that you are invoking the command after C++ buffer is setup. Thus key binding in C++ is relevant.

@fperies
Copy link
Contributor Author

fperies commented Jun 18, 2020

@emacs18 Ok I understand your point.
I'm just saying it is not me who is calling interactively the newline-and-indent command. I think this is the consequence of execution of widget-button-click function when the click is short.

Here is a short illustration of my issue when I click on the first recent file:
test
As you can see an undesired line is inserted at point in the destination buffer.

@emacs18
Copy link
Contributor

emacs18 commented Jun 18, 2020

You may not call newline-and-indent intentionally. However the stack trace indicates that you are calling it by some action you took, i.e., the function was not called via some other function, e.g., following is the stack trace if I type SPC j k within c++ file which shows how the stack trace looks if the function was called via some other function:

Debugger entered--entering a function:
* newline-and-indent()
  (while (> counter 0) (join-line 1) (newline-and-indent) (setq counter (1- counter)))
  (let ((counter (or count 1))) (while (> counter 0) (join-line 1) (newline-and-indent) (setq counter (1- counter))))
  spacemacs/evil-goto-next-line-and-indent(1)
  funcall-interactively(spacemacs/evil-goto-next-line-and-indent 1)
  call-interactively(spacemacs/evil-goto-next-line-and-indent nil nil)
  command-execute(spacemacs/evil-goto-next-line-and-indent)

The only explanation I can think of is that you have somehow customized your mouse key bindings which ends up calling the command in question. Could this also be a mouse hardware problem? I have no idea.

@fperies
Copy link
Contributor Author

fperies commented Jun 19, 2020

I fully agree with you: the newline-and-indent function is not called from another function.

I've done two tries from startup and invoked command describe-last-keys :

  • if I "short" click on first recent file I get:
#### Emacs last keys :musical_keyboard: 
   text
r <down-mouse-1> <mouse-1> <mouse-1> RET M-m h d l
  • if I "long" click on first recent file I get:
#### Emacs last keys :musical_keyboard: 
   text
r <down-mouse-1> <mouse-1> M-m h d l

So I don't think this is a mouse hardware problem and it seems something is inserting implicitly a RET key when mouse button is quickly released.

I really don't see how to catch the way this is done. Any clue ?

P.S/ I don't have any particular mouse key bindings in my configuration file except:
(setq mouse-wheel-scroll-amount '(1 ((shift) . 5) ((control))))

@duianto
Copy link
Contributor

duianto commented Jun 25, 2020

This sounds like it might be the same/similar issue as described in:
Auto paste into the files opened by mouse-click the item below Recent Files in Spacemacs buffer #5435

The issue is labeled as macOS, but here's at least one report from a Linux user:
Newly opened files get an instant clipboard paste #12163

This seems to be the most up voted workaround: #5435 (comment)

;; This problem may be related with wid-edit.el and mouse-1-click-follows-link.
;; Now I can avoid automatic yank by putting the following config in
;; spacemacs/user-config.
(add-hook 'spacemacs-buffer-mode-hook
          (lambda () (set (make-local-variable
                           'mouse-1-click-follows-link)
                          nil)))

@fperies
Copy link
Contributor Author

fperies commented Jun 25, 2020

@duianto : Thank you very much for your answer!
This seems effectively to be the same issue and the proposed workaround works like a charm.

Thx again !

@fperies fperies closed this as completed Jun 25, 2020
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