spacemacs icon indicating copy to clipboard operation
spacemacs copied to clipboard

Spacemacs inserts a newline in cursor place after exiting (C-x C-c).

Open mateodif opened this issue 5 years ago • 14 comments

Description :octocat:

Spacemacs inserts a newline in cursor place after exiting (C-x C-c). Not intended behavior. Affects spacemacs, spacemacs-base, ivy and helm alike. I use emacs keybindings.

Reproduction guide :beetle:

  • Start Emacs
  • Open file
  • Exit using C-x C-c
  • Emacs will ask if you want to save changes (Why would it? We just wanted to exit)
  • If yes, the file will have a newline after opening the file again

Observed behaviour: :eyes: :broken_heart: A newline is inserted after exiting.

Expected behaviour: :heart: :smile: The file should be intact after exiting, as we did not modify it whatsoever.

System Info :computer:

  • OS: gnu/linux
  • Emacs: 26.1
  • Spacemacs: 0.200.13
  • Spacemacs branch: master (rev. c7a103a77)
  • Graphic display: t
  • Distribution: spacemacs-base
  • Editing style: emacs
  • Completion: ivy
  • Layers:
(ivy emacs-lisp)
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 MODULES THREADS LIBSYSTEMD LCMS2

mateodif avatar Dec 19 '18 19:12 mateodif

Bumping this thread as this still applies to latest spacemacs. Am I the only one experiencing this?

mateodif avatar Feb 19 '19 15:02 mateodif

That is a feature, not an issue. Many files I have seen, have a newline at the end of the file. You can turn off this feature by setting require-final-newline to nil.

Compro-Prasad avatar Feb 20 '19 12:02 Compro-Prasad

I double checked and it doesn't seem to affect the bug I'm talking about. My issue is about the creation of newlines in the place the cursor was before it was saved and closed, not the final newline that is added to all texts.

mateodif avatar Feb 20 '19 15:02 mateodif

That is a feature, not an issue. Many files I have seen, have a newline at the end of the file. You can turn off this feature by setting require-final-newline to nil.

Actually, (setq require-final-newline nil) won't work, value of require-final-newline is still t, you have to set (setq-default mode-require-final-newline nil)

c02y avatar Jun 10 '19 08:06 c02y

I believe the newline is inserted when you open a file by clicking on the file name from the spacemacs home page. Try click on a file from the spacemacs home page and then C-/ it will undo the newline inserted to the buffer. I noticed the newline is inserted after the cursor position not at the end of file.

And try open the file by C-x C-f, it won't insert newline

hamadmarri avatar Jan 24 '20 04:01 hamadmarri

@mateodif Please check kill-emacs-hook.

Compro-Prasad avatar Jan 25 '20 07:01 Compro-Prasad

The second reproduction step needs to clarify how the file is opened:

Open file

If it only occurs as hamadmarri suggests. When mouse clicking on a file in the Spacemacs home buffer, then it sounds like this issue: Auto paste into the files opened by mouse-click the item below Recent Files in Spacemacs buffer #5435

This seems to be the most up voted work-around: https://github.com/syl20bnr/spacemacs/issues/5435#issuecomment-195862080

duianto avatar Jan 26 '20 18:01 duianto

I have the same issue on macos. @duianto , that solution doesn't work for me; I just get control code printed to minibuffer when clicking on links (in dumb terminal).

paxperscientiam avatar Mar 10 '20 05:03 paxperscientiam

@paxperscientiam Could you provide some reproduction steps and include your system info. Press SPC h d s to copy your system info to the clipboard.

It would also be helpful if your able to copy the buffers contents both before and after the issue occurs. If your unable to copy the contents, then you can post screenshots.

duianto avatar Mar 10 '20 14:03 duianto

I believe the newline is inserted when you open a file by clicking on the file name from the spacemacs home page. Try click on a file from the spacemacs home page and then C-/ it will undo the newline inserted to the buffer. I noticed the newline is inserted after the cursor position not at the end of file.

And try open the file by C-x C-f, it won't insert newline

I can confirm it does insert the new line ONLY when you click the on the file in the landing buffer.

System Info :computer:

  • OS: gnu/linux
  • Emacs: 26.1
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. c9c5637ac)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: emacs
  • Completion: helm
  • Layers:
(javascript helm auto-completion emacs-lisp git markdown html syntax-checking erlang elm)
  • System configuration features: XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 THREADS LIBSYSTEMD LCMS2

memer-boy avatar Apr 10 '20 15:04 memer-boy

@memer-boy As I mentioned in the comment above ☝️ https://github.com/syl20bnr/spacemacs/issues/11733#issuecomment-578527067

There's an open issue about that: Auto paste into the files opened by mouse-click the item below Recent Files in Spacemacs buffer #5435

it has an up voted workaround: https://github.com/syl20bnr/spacemacs/issues/5435#issuecomment-195862080

;; 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)))

duianto avatar Apr 13 '20 16:04 duianto

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

github-actions[bot] avatar Oct 17 '21 11:10 github-actions[bot]

I actually participated in a discussion over at emacs-dashboard/emacs-dashboard about this very issue. Long story short, there's a solution that can now be adopted.

https://github.com/emacs-dashboard/emacs-dashboard/pull/285

paxperscientiam avatar Nov 14 '21 07:11 paxperscientiam

Actually, (setq require-final-newline nil) won't work, value of require-final-newline is still t, you have to set (setq-default mode-require-final-newline nil)

In my case, (setq require-final-newline nil) worked, and (setq-default mode-require-final-newline nil) didn't. 🤷‍♂️

upbqdn avatar May 20 '22 16:05 upbqdn