簡體   English   中英

如何改變emacs上的cursor顏色

[英]How to change the cursor color on emacs

我對 Emacs 的 colors 進行了一些更改,現在唯一錯誤的是黑色背景上的黑色 cursor,我將不得不更改它。 我該怎么辦?

如果您運行的是最新版本的 emacs,您可以使用:

; Set cursor color to white
(set-cursor-color "#ffffff") 

您可以使用任何您喜歡的顏色來代替#ffffff 對於十六進制代碼列表,谷歌說: http : //www.tayloredmktg.com/rgb/


也許你喜歡這個……下面的代碼在每次閃爍時改變光標顏色。 只需評估代碼及其運行:

; Using in Emacs 24.0 

(defvar blink-cursor-colors (list  "#92c48f" "#6785c5" "#be369c" "#d9ca65")
  "On each blink the cursor will cycle to the next color in this list.")

(setq blink-cursor-count 0)
(defun blink-cursor-timer-function ()
  "Zarza wrote this cyberpunk variant of timer `blink-cursor-timer'. 
Warning: overwrites original version in `frame.el'.

This one changes the cursor color on each blink. Define colors in `blink-cursor-colors'."
  (when (not (internal-show-cursor-p))
    (when (>= blink-cursor-count (length blink-cursor-colors))
      (setq blink-cursor-count 0))
    (set-cursor-color (nth blink-cursor-count blink-cursor-colors))
    (setq blink-cursor-count (+ 1 blink-cursor-count))
    )
  (internal-show-cursor nil (not (internal-show-cursor-p)))
  )

請注意,此代碼替換了“frame.el”中的 emacs 函數“blink-cursor-timer-function”。

以上都不適合我,所以我自己做了一些研究。 來自 EmacsWiki:

14.20 顯示光標

在文本終端上,光標的外觀由終端控制,很大程度上不受 Emacs 的控制。 一些終端提供兩種不同的光標:“可見”的靜態光標和“非常可見”的閃爍光標。 默認情況下,Emacs 使用非常明顯的光標,並在您啟動或恢復 Emacs 時切換到它。 如果 Emacs 啟動或恢復時變量 visible-cursor 為 nil,則它使用普通光標。

在圖形顯示上,可以更改文本光標的更多屬性。 要自定義其顏色,請更改名為 cursor 的面的 :background 屬性(請參閱面自定義)。 (這張臉的其他屬性沒有影響;光標下顯示的文本是使用框架的背景色繪制的。)要更改其形狀,請自定義緩沖區局部變量 cursor-type; 可能的值為 box(默認值)、hollow(空心框)、bar(垂直條)、(bar .n)(垂直條 n 像素寬)、hbar(水平條)、(hbar .n)(一個水平條 n 像素高),或 nil(根本沒有光標)。

要禁用光標閃爍,請將變量 blink-cursor-mode 更改為 nil(請參閱 Easy Customization),或將 (blink-cursor-mode 0) 行添加到您的 init 文件中。 或者,您可以通過自定義列表變量blink-cursor-alist 來更改光標“閃爍”時的外觀。 列表中的每個元素都應該具有 (on-type . off-type) 形式; 這意味着如果光標在閃爍時顯示為 on-type(其中 on-type 是上述光標類型之一),那么它在閃爍時顯示為 off-type。

某些字符,例如制表符,是“超寬”的。 當光標定位在這樣的字符上時,它通常以默認字符寬度繪制。 通過將變量 x-stretch-cursor 更改為非 nil 值,您可以使光標拉伸以覆蓋寬字符。

光標通常在未選擇的窗口中顯示為不閃爍的空心框。 (對於條形光標,它顯示為更細的條形。)要關閉非選定窗口中的光標,請將變量 cursor-in-non-selected-windows 更改為 nil。

為了使光標更加可見,您可以使用 HL 線模式,這是一種突出顯示包含點的線的次要模式。 使用 Mx hl-line-mode 在當前緩沖區中啟用或禁用它。 Mx global-hl-line-mode 全局啟用或禁用相同的模式。

所以這里是這樣做的方法: 1. Mx customize-face ,輸入 2. cursor輸入 3. 選擇你喜歡的背景顏色。 4.點擊狀態,保存以備將來使用。

截圖在這里:

在此處輸入圖片說明

在此處輸入圖片說明

在此處輸入圖片說明

在此處輸入圖片說明

試試這個:

(setq default-frame-alist
  '((cursor-color . "palegoldenrod")))

如果您想保留default-frame-alist的其他值,您可以使用 Mark 的建議:

(add-to-list 'default-frame-alist '(cursor-color . "palegoldenrod"))

如果您使用 X 窗口系統,請嘗試將這樣的內容放入.Xdefaults

*cursorColor: #ff7700

還有一個命令行選項:

--cursor-color, -cr COLOR       color of the Emacs cursor indicating point

您可以使用它來自定義 emacs 顏色:

(defun good-colors ()
  (progn
     ;; Set cursor color
     (set-cursor-color "Black")

     (set-background-color "grey46")
     (set-foreground-color "White")
     (set-border-color "dark orange")
     (set-mouse-color "dark orange") 
))

(good-colors)

對我來說,根據其他答案的建議在 init 上設置光標顏色不會真正起作用,因為可能會干擾我正在加載的主題和包。 我的解決方案是添加以下內容:

(add-hook 'after-init-hook
          (lambda () (run-with-timer 5 nil #'set-cursor-color "SystemRedColor")))

這個解決方案使得對 set-cursor-color 的調用只會在 init 完成后 5 秒發生,為所有其他包和主題更改提供足夠的時間來完全加載。

請記住,如果您使用的是iTerm2 ,則必須對其設置進行更改,否則不會對.emacs配置文件進行更改。

Preferences => Profiles => Color => Cursor Colors

在此處輸入圖片說明

我將(set-face-attribute 'cursor nil:background "#A0F")添加到我的.emacs文件中,使我的 cursor 變成漂亮的紫羅蘭色。

我不確定版本和系統信息有多重要,但我在 Ubuntu 22.04.1 LTS 上以 GUI 模式運行 GNU Emacs 27.1。 (Emacs 28.2 可以從 GNU 網站獲得,所以 YMMV。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM