elisp

Check if a string ends with a suffix in Emacs Lisp

拥有回忆 提交于 2019-12-08 17:05:55
问题 Is there a function that checks that a string ends with a certain substring? Python has endswith: >>> "victory".endswith("tory") True 回答1: Just install s.el string manipulation library and use its s-suffix? predicate: (s-suffix? "turn." "...when it ain't your turn.") ; => t But if you refuse you to use this library, you have to write your own function. There is string-prefix-p, which is an analog to Python's str.startswith, in subr.el , and it is just a wrapper around compare-strings.

How does a progn form in font-lock-keywords work?

怎甘沉沦 提交于 2019-12-08 13:34:36
问题 Following code will visually replace "hello world" with "HW" by passing a progn form to font lock keywords. (font-lock-add-keywords nil '(("\\(hello world\\)" (0 (progn (put-text-property (match-beginning 1) (match-end 1) 'display "HW") nil))))) I've look into C-h v font-lock-keywords to see if this is a documented feature of font lock. The hello world element seemed to be of this form: (MATCHER HIGHLIGHT ...) which would mean that (0 ...) is HIGHLIGHT and the doc says HIGHLIGHT should be

How to modularize the common functionality of two Lisp functions handling Java files?

≯℡__Kan透↙ 提交于 2019-12-08 08:23:10
问题 I use one Lisp function to compile the current Java file and another to run it. Both functions use the same functionality to get the package name and the appropriate directory to compile/run from (this functionality was posted as an answer to another question). I would like to modularize the common functionality of these functions, i.e. from (let* to but not including (cd . How can I do this? As bonus I would like to undo the changing of directory (the cd :ing) as the functions are done to

Searching with intelligent bracket counting (Elisp)

微笑、不失礼 提交于 2019-12-08 07:42:37
问题 I have the following function that deletes the LaTeX command surrounding the current cursor position: (defun remove-tex-cmd () (interactive) (save-excursion (let (cur-point beg-point end-point) (setq cur-point (point)) (catch 'notexcmd (if (not (re-search-backward "\\.*?{" nil t)) ; now the point is at the { (throw 'notexcmd nil)) (search-backward "\\" nil t) (setq beg-point (point)) (re-search-forward "}") (setq end-point (point)) (if (> end-point cur-point) (kill-region beg-point end-point)

Splitting window in Emacs Lisp function

ε祈祈猫儿з 提交于 2019-12-08 05:26:35
问题 I'd like to be able to run a shell command on the current file that I'm editing and have the output be shown in the Shell Command Output window. I've been able to define the function which is shown below. (defun cpp-check () "Run cpp-check on current file the buffer is visiting." (shell-command (concat "/home/sburke/downloads/cppcheck-1.31/cppcheck " (buffer-file-name)))) The only problem is that the output window isn't brought to the foreground in any way. What I'd like to happen is for the

Emacs: Make custom scrolling function follow mouse but not change keyboard focus

会有一股神秘感。 提交于 2019-12-08 02:37:45
问题 I have some custom scrolling functions in Emacs, which help me get around a bug where a single scroll event sends two <mouse-4> or <mouse-5> actions. I have: (setq scroll-down-this-time t) (defun my-scroll-down-line () (interactive "@") (if scroll-down-this-time (progn (scroll-down-line) (setq scroll-down-this-time nil)) (setq scroll-down-this-time t))) (setq scroll-up-this-time t) (defun my-scroll-up-line () (interactive "@") (if scroll-up-this-time (progn (scroll-up-line) (setq scroll-up

“value returned is unused” warning when byte-compiling a macro

邮差的信 提交于 2019-12-07 22:30:05
问题 Why does byte-compiling the the following produce a warning? (defmacro foomacro (shiftcode) `(defun foo (&optional arg) (interactive ,(concat shiftcode "p")) (message "arg is %i" arg)) `(defun bar (&optional arg) (interactive ,(concat shiftcode "Nenter a number: ")) (message "arg is %i" arg))) ;; provide backward compatibility for Emacs 22 (if (fboundp 'handle-shift-selection) (foomacro "^") (foomacro "")) This is the warning I get: $ emacs -Q --batch --eval '(byte-compile-file "foo.el")' In

Beginning and end of the string in Emacs regexps

别来无恙 提交于 2019-12-07 16:39:45
问题 What is the characters that indicate the beginning and the end of the string with newlines in it? I'm writing a trim function: (defun trim (str) (if (string-match "^[[:space:]]*\\(.+?\\)[[:space:]]*$" str) (match-string 1 str) str)) But with a string like "first/nnext" (got from shell-command-to-string ) it returns only the "first". Reference manual says: When matching a string instead of a buffer, ‘^’ matches at the beginning of the string or after a newline character. \\' and the left one

emacs isearch lazy highlight for whole buffer

好久不见. 提交于 2019-12-07 15:39:38
问题 the default behavior of isearch was highlighting the world that matched in current windows. how can i change that behavior, let it highlighting the world that matched in the whole current buffer. 回答1: Perhaps you are looking for the highlight-* commands, to keep things highlighted throughout the buffer whilst you perform other actions? M-s h C-h lists: Global Bindings Starting With M-s h: key binding --- ------- M-s h l highlight-lines-matching-regexp M-s h p highlight-phrase M-s h r

Converting number to base-2 (binary) string representation [duplicate]

≯℡__Kan透↙ 提交于 2019-12-07 15:33:20
问题 This question already has an answer here : How to display numbers in different bases under elisp? (1 answer) Closed 5 years ago . I'd like to convert a number to a binary string, e.g. (to-binary 11) -> "1011". I already found a method to convert to hex and oct: (format "%x" 11) -> "B" (format "%o" 11) -> "13" but there is apparently no format string for binary ("%b" gives an error). The conversion is simple the other way round: (string-to-number "1011" 2) -> 11 Is there any other library