2

When using (set-default 'truncate-lines t), and when moving to the end of the long line, is it possible to make Emacs scroll only that line, while the other lines stand still? nano does this.

forthrin
  • 451
  • 2
  • 10

2 Answers2

2

Emacs 26 has a new feature to horizontal scroll the current line when the variable truncate-lines is also non-nil. The variable to control that new feature is auto-hscroll-mode and the relevant portion from the doc-string reads: "... The value 'current-line means the line displaying point in each window is automatically scrolled horizontally to make point visible." The auto-hscroll-mode variable is global. The variable truncate-lines is buffer-local when set. My personal preference is to use auto-hscroll-mode on a buffer-local basis, which generally means that the major-mode must be activated in the buffer before setting these variables:

(setq truncate-lines t)
(setq-local auto-hscroll-mode 'current-line)

As suggested in a comment by @Basil hereinbelow, it would behoove anyone who is interested in the horizontal scrolling feature to read the relevant portion from the Emacs manual: https://www.gnu.org/software/emacs/manual/html_node/emacs/Horizontal-Scrolling.html [Inasmuch as Emacs 26 has not yet been officially released, it may be a few months before the on-line manual is updated with this particular new feature.]

In a comment by the O.P. underneath an alternative answer, there was a question about exclusions to a variable such as truncate-lines. The way in which that particular variable is used does not contemplate exclusions. The default value is nil. One could change the default value to a non-nil value using setq-default, and override that setting on a buffer-local basis by using a major-mode hook to set the value to nil using setq.

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • I recommend linking to the manual node which describes all of this in more detail: [`(emacs) Horizontal Scrolling`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Horizontal-Scrolling.html); otherwise, +1. – Basil Apr 08 '18 at 17:16
  • (add-hook 'rmail-mode-hook '(lambda () (setq truncate-lines nil))) – forthrin Apr 08 '18 at 18:18
  • @forthrin It's better not to quote `lambda`s: `(add-hook 'rmail-mode-hook (lambda () (setq truncate-lines nil)))`. – Basil Apr 08 '18 at 19:12
0

Not with out-of-the-box Emacs, I believe. But maybe someone will kindly provide an answer (e.g. code) that does that.

My suggestion is to use M-x report-emacs-bug to request this as an enhancement (that command is also for enhancement requests). Essentially, you want to be able to scroll a single line (or perhaps selected lines - the lines in the active region). That might be useful.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • I'm not sure when this was introduced as a *feature*, but I use it in my own setup: `(setq-local auto-hscroll-mode 'current-line)` as a buffer-local setting: "*... The value `‘current-line` means the line displaying point in each window is automatically scrolled horizontally to make point visible.*" – lawlist Apr 07 '18 at 04:13
  • @lawlist: Please consider posting that as an answer. It sounds like an answer, or at least the makings of one (arbitrary line vs current line). – Drew Apr 07 '18 at 04:39
  • @lawlist: I couldn't get the `auto-hscroll-mode` thing to work (Emacs 25.3.1). PS! I'm not on the mailing list, but anyone please do post a feature request. Today's way of moving the entire buffer is not good. – forthrin Apr 08 '18 at 06:09
  • @forthrin -- I haven't Googled and searched the latest new feature, but I would suggest just looking at your doc-string with `C-h f` or `M-x describe-variable`. If it contains the exact quote mentioned in the first comment, then you are good to go. If not, then you'll need Emacs 26 ... (not yet released to the general public, but is available to anyone who wants to build from source or download a nightly build from a variety of sources depending upon the OS). [I added it manually to a pre-Emacs 25 release several months ago so that I can work on my own feature requests implemented in C...] – lawlist Apr 08 '18 at 06:28
  • @lawlist: "Allow or disallow automatic horizontal scrolling of windows. If non-nil, windows are automatically scrolled horizontally to make point visible." – forthrin Apr 08 '18 at 06:38
  • @forthrin -- then, there you have it. It must be an Emacs 26 feature. It is possible to patch an older version like I did, but you should use Emacs 26 if you would like to experiment with that new feature. I think there is a release candidate available, but I have just used the Emacs 26 branch when communicating with the Emacs team to report bugs and seek guidance on the feature requests that I am working on (almost 2 years now ... and presently stuck ... :) ). – lawlist Apr 08 '18 at 07:26
  • @lawlist: Hip hop hurray. `(setq-default truncate-lines t) (setq-default auto-hscroll-mode 'current-line)` does like `nano` in Emacs 26. You may post this as a answer. For bonus points, include how `truncate-lines` can be set for all modes except a list of certain modes. My native attempt `(setq truncate-lines '(not rmail-mode))` did not work. – forthrin Apr 08 '18 at 07:43