天道酬勤,学无止境

elisp

Set Emacs to smart auto-line after a parentheses pair?

I have electric-pair-mode on (which isn't really particularly relevant, as this could apply to any auto-pairing mode or even manual parens), but in a nutshell, I'd like it so that in the case I have: function foo() {|} (where | is the mark) If I press enter, I would like to have it automatically go to function foo() { | } It would also mean that function foo(|) {} would become function foo( | ){} I already have things to take care of the indentation, but I'm not sure how to say "if I'm inside any empty pair of matched parenthesis, when I press return, actually insert two new lines and put me

2021-06-15 10:43:40    分类:问答    emacs   elisp

Change Emacs Mode-Line color based on major-mode

I like to see if there is a way to change the mode-link foreground and background color base on the major-mode, I was thinking to add the logic in the (add-hook 'after-change-major-mode-hook But, I do not have all the emacs lisp experience to make such change. Here is the logic: switch major-mode: case "emacs-lisp-mode": (set-face-foreground 'mode-line "ivory") (set-face-background 'mode-line "DarkOrange2") case "ruby-mode": (set-face-foreground 'mode-line "white") (set-face-background 'mode-line "red") ... default: (set-face-foreground 'mode-line "black") (set-face-background 'mode-line

2021-06-15 04:33:38    分类:问答    emacs   elisp   emacs-faces   modeline

Switching between color themes in Emacs ( < v.24)

Update: Note that this thread does not applyt o recent versions of Emacs (24+). Emacs now comes with it's own powerful color theming system (e.g. see a review here) that does not required loading the external package color-theme . I have the following code snippet in my .emacs file, where I defined a few aliases that allow me to switch conveniently between a couple of color themes using short extended commands: (require 'color-theme) (eval-after-load "color-theme" '(progn (color-theme-initialize) (color-theme-aalto-light))) ;; Aliases to color-themes, e.g. 'M-x a' switches to color-theme-hober

2021-06-14 19:40:04    分类:问答    emacs   elisp

Open dired and select the file associated with the previous buffer?

Let's say I am editing blah.txt with Emacs and I decide to open dired to rename the file blah.txt. When I press C-x d RET (or C-x C-f RET), a dired buffer will show up to display the content of the directory containing blah.txt, but the cursor will not be on blah.txt. So I need to search my file first (C-s blah.txt) to place my cursor on it and then I can rename it (R). How do I automate or remove the step C-s blah.txt?

2021-06-14 18:11:54    分类:问答    emacs   elisp   rename   dired

How to calculate difference between two sets in emacs lisp,the sets should be lists

How to calculate the difference between two sets in Emacs Lisp? The sets should be lists. The programm should be very simple and short, or else I won't understand it. I'm a newbee. Thx

2021-06-14 11:19:04    分类:问答    lisp   elisp   set   set-difference

Why not quoting lambda?

I was told that I shouldn't quote lambda in, say, (global-set-key (quote [f3]) '(lambda () (interactive) (other-window -1) )) I tried that indeed if I don't quote lambda, it works equally well (global-set-key (quote [f3]) (lambda () (interactive) (other-window -1) )) However, I don't understand why the latter works (and is also being preferred, and now that the latter works, why the former also works). If the lambda expression is defined as an other function, we would have called (global-set-key (quote [f3]) 'my-function) to prevent my-function to be evaluated immediately. I understand the

2021-06-14 04:25:12    分类:问答    emacs   elisp

Emacs Lisp: getting ascii value of character

I'd like to translate a character in Emacs to its numeric ascii code, similar to casting char a = 'a'; int i = (int)a in c. I've tried string-to-number and a few other functions, but none seem to make Emacs read the char as a number in the end. What's the easiest way to do this?

2021-06-14 03:52:05    分类:问答    char   elisp   ascii

Does learning one Lisp help in learning the other?

Is there any synergy between learning different Lisp languages? I'm currently learning Emacs Lisp, as it is immediately useful in my daily Emacs usage, however i'm fascinated with all Lisps, so maybe someday i will learn and use others. Will learning Emacs Lisp help me, when i start digging in Common Lisp, Scheme or Clojure? In other words, will it be for me like learning a completely new language, or some notions and paradigms are common? I'm also interested in comparison of unique differences between the Lisps, which will be a problem, when i come from one Lisp to another. In How to go about

2021-06-14 02:23:10    分类:问答    clojure   lisp   scheme   elisp   common-lisp

How to call interactive Emacs Lisp function with a prefix argument, from another Emacs Lisp function?

I want to write an Emacs Lisp function that will turn on flyspell-mode regardless of the current state of the mode. Function flyspell-mode-on is deprecated. The documentation suggests that a positive prefix argument will turn flyspell-mode, but unfortunately running (flyspell-mode 1) results in an error message: Wrong number of arguments: (lambda (flyspell-mode 1)), 0 If I could figure out how to call flyspell-mode with a prefix argument, I believe I could solve this problem. The most relevant section I can find in the Emacs Lisp manual is the section entitled "Interactive Call", which

2021-06-13 08:56:11    分类:问答    emacs   elisp

How to turn off electric-indent-mode for specific Major mode?

I have few Major modes (like: Yaml and NXML) that I don't want electric-indent-mode (I want it for C like languages) but I'm unable to turn if off. To enable I have: (electric-indent-mode 1) from documentation (for variable electric-indent-mode) Non-nil if Electric-Indent mode is enabled. See the command electric-indent-mode' for a description of this minor mode. Setting this variable directly does not take effect; either customize it (see the info nodeEasy Customization') or call the function `electric-indent-mode'. and for a function Toggle on-the-fly reindentation (Electric Indent mode)

2021-06-13 08:18:51    分类:问答    emacs   elisp   major-mode