From: JOE Staursky <jnstaursky@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Eval-buffer works, init does not hl-line fix
Date: Thu, 30 Jun 2016 22:20:29 +0000 [thread overview]
Message-ID: <CAH5NKWnsM1KPKqnK=Tp4eMHwboBnJ8=6EKNLrEgG837xRTH0tQ@mail.gmail.com> (raw)
I have written the following bit of emacs lisp that allows hl-line to
extend past end of buffer to the rest of the line.
Problem is, this only works if I use (eval-buffer) after start-up and not
when I have it saved inside my .emacs file.
However,
I doubt that could cause this sort of difficulty.
Basically I am trying to make the current highlight line act more like
contemporary editors.
what could be interfering in the init file but not while in buffer?
(defvar-local hl-line-after-cursor nil
"Overlay used by Global-Hl-Line mode to highlight the current line.")
(defun my-hl-line-after-current-line()
(if (eq (line-end-position) (point-max))
(progn
(setq hl-line-after-cursor (make-overlay
(line-end-position) (line-end-position)))
(overlay-put hl-line-after-cursor 'after-string
(propertize (make-string (- (-
(window-text-width) (- (line-end-position) (line-beginning-position)))
2) (string-to-char " "))
'face hl-line-face 'cursor 1))
(move-overlay hl-line-after-cursor (line-end-position)
(line-end-position))
)))
(defun my-hl-line-after-unhighlight ()
"Deactivate the Hl-Line overlay on the current line."
(when hl-line-after-cursor
(delete-overlay hl-line-after-cursor)))
(add-hook 'pre-command-hook #'my-hl-line-after-unhighlight nil t)
(add-hook 'post-command-hook #'my-hl-line-after-current-line nil t)
my init file
(setq user-full-name "YOUR NAME")
(setq user-mail-address "YOUR EMAIL ADDRESS")
;;
;; Basic Setup
;;
(prefer-coding-system 'utf-8)
;; Shorten yes-or-no prompts
(fset 'yes-or-no-p 'y-or-n-p)
;; This code stashes backups in ~/.emacs.d/backups
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
;; This code removes the ugly tool bar
(tool-bar-mode -1)
;; Matching parenthesis highlight
(show-paren-mode 1)
;; Show line numbers
(global-linum-mode 1)
;; Set window title to full file name
(setq frame-title-format '("Emacs @ " system-name ": %b %+%+ %f"))
;; Set up smooth scrolling
(setq redisplay-dont-pause t
scroll-margin 1
scroll-step 1
scroll-conservatively 10000
scroll-preserve-screen-position 1)
;; get rid of the scroll bar boxes
(scroll-bar-mode -1)
;; Set the tab width to 2 by default
(setq-default tab-width 2)
;; No dinging during exceptions
(setq visible-bell 1)
;; Enable keybinding to Caps Lock key
(setq w32-enable-caps-lock nil)
;; Highlight current line
(global-hl-line-mode +1)
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(package-initialize)
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(load-theme 'solarized t)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes
(quote
("a8245b7cc985a0610d71f9852e9f2767ad1b852c2bdea6f4aadc12cce9c4d6d0"
default))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; The default "C-x c" is quite close to "C-x C-c", which quits Emacs.
;; Changed to "C-c h". Note: We must set "C-c h" globally, because we
;; cannot change `helm-command-prefix-key' once `helm-config' is loaded.
(global-set-key (kbd "C-c h") 'helm-command-prefix)
(global-unset-key (kbd "C-x c"))
(global-set-key (kbd "M-x") 'helm-M-x)
; (add-to-list 'load-path "~/site-lisp/wolfram-mode-master/")
; (require wolfram-mode)
; (autoload 'wolfram-mode "wolfram-mode" nil t)
; (autoload 'run-wolfram "wolfram-mode" nil t)
; (setq wolfram-program "C:\ProgramData\Microsoft\Windows\Start
Menu\Programs\Wolfram Mathematica")
; (add-to-list 'auto-mode-alist '("\\.m$" . wolfram-mode))
; (setq wolfram-path "C:\Program Files\Wolfram
Research\Mathematica\10.4") ;; e.g. on Linux
"~/.Mathematica/Applications"
;(overlay-put (make-overlay (line-end-position) (point-max))
'after-string (propertize " " 'face '(:background "gray50" :foreground
"black")))
(defvar-local hl-line-after-cursor nil
"Overlay used by Global-Hl-Line mode to highlight the current line.")
(defun my-hl-line-after-current-line()
(if (eq (line-end-position) (point-max))
(progn
(setq hl-line-after-cursor (make-overlay
(line-end-position) (line-end-position)))
(overlay-put hl-line-after-cursor 'after-string
(propertize (make-string (- (-
(window-text-width) (- (line-end-position) (line-beginning-position)))
2) (string-to-char " "))
'face hl-line-face 'cursor 1))
(move-overlay hl-line-after-cursor (line-end-position)
(line-end-position))
;(overlay-put hl-line-after-cursor 'priority -50)
)))
(defun my-hl-line-after-unhighlight ()
"Deactivate the Hl-Line overlay on the current line."
(when hl-line-after-cursor
(delete-overlay hl-line-after-cursor)))
(add-hook 'pre-command-hook #'my-hl-line-after-unhighlight nil t)
(add-hook 'post-command-hook #'my-hl-line-after-current-line nil t)
next reply other threads:[~2016-06-30 22:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-30 22:20 JOE Staursky [this message]
2016-07-01 3:50 ` Eval-buffer works, init does not hl-line fix Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH5NKWnsM1KPKqnK=Tp4eMHwboBnJ8=6EKNLrEgG837xRTH0tQ@mail.gmail.com' \
--to=jnstaursky@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).