2

I wanted something that highlighted a snippet of code that I wanted to keep in mind - NOT marking it, I just want it to pop out visually. As a bonus, I'd like it to get pushed to the mark ring so I can navigate back to it easily. highlight.el and similar packages are annoying though, because if the region is not active, they'll highlight the entire buffer - for what reason, I have no idea but it makes them unusable imo, as I want to be able to tag stuff with a single keystroke. So:

;; highlights line if region not active
(defun highlight-region (beg end)
  (interactive "r")
  (unless  (use-region-p)
    (setq beg (line-beginning-position))
    (setq end (line-end-position)))
  (push-mark beg)
  (set-text-properties
   beg end
   '(font-lock-face (:background "yellow" :foreground "black")
                    highlighted t
                    help-echo "highlighted")))

This works great, along with some related functions I stole from somewhere. But what I'd like is for the full line, from col 1 to col 80, to be highlighted - not just the columns that contains text and none of the overflow at col 81+. I'd need something like

(setq end (point-at-col 80))

does something like this exist?

  • 1
    It's not so simple: if the current line is less than 80 columns, then there is no suitable point value for (point-at-col 80) to return. – npostavs Oct 10 '17 at 17:04
  • Your specification of what you request is unclear. You want more than the text on the current line to be highlighted, and you want whatever is highlighted to be added to the kill-ring. If the text on the current line does not cover all 80 columns, what text do you expect to be added to the kill-ring? – Drew Oct 10 '17 at 18:01
  • @Drew He/she wants to push the point at the beginning of the selected region (or the unselected line) onto the MARK ring. He/she does not mention the kill-ring – Benjamin Lindqvist Oct 10 '17 at 18:36
  • @BenjaminLindqvist: Ah, right. Still, marks happen only for buffer positions, not for screen positions that are, e.g., past the end of the text on a line. The highlight requested will sometimes go past the end of the line text. That end cannot be "marked". – Drew Oct 10 '17 at 19:50
  • That's not what @yafov wants to do anyway. The mark to be pushed is the point at the BEGINNING of the region/line – Benjamin Lindqvist Oct 10 '17 at 19:58
1

It IS that simple:

(unless  (use-region-p)
    (setq beg (line-beginning-position))
    (setq end (+ 1 (line-end-position))))

(Although this will actually highlight the full line, not stopping at col 80)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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