3

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.

2 Answers 2

3

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.

3
  • I recommend linking to the manual node which describes all of this in more detail: (emacs) Horizontal Scrolling; otherwise, +1.
    – Basil
    Commented Apr 8, 2018 at 17:16
  • (add-hook 'rmail-mode-hook '(lambda () (setq truncate-lines nil)))
    – forthrin
    Commented Apr 8, 2018 at 18:18
  • @forthrin It's better not to quote lambdas: (add-hook 'rmail-mode-hook (lambda () (setq truncate-lines nil))).
    – Basil
    Commented Apr 8, 2018 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.

7
  • 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
    Commented Apr 7, 2018 at 4: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
    Commented Apr 7, 2018 at 4: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
    Commented Apr 8, 2018 at 6: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
    Commented Apr 8, 2018 at 6:28
  • @lawlist: "Allow or disallow automatic horizontal scrolling of windows. If non-nil, windows are automatically scrolled horizontally to make point visible."
    – forthrin
    Commented Apr 8, 2018 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.