elisp

how to check if emacs in frame or in terminal?

▼魔方 西西 提交于 2019-12-23 09:23:43
问题 Based on this question : How to set emacsclient background as Emacs background? I need background only for frames, not for terminal and not for console. Here is how I'm trying to add fix for console (when (display-graphic-p) (tool-bar-mode -1) (scroll-bar-mode t) (require 'nyan-mode) (nyan-mode) (nyan-start-animation) (mouse-wheel-mode t) (setq default-frame-alist '((background-color . "#101416") (foreground-color . "#f6f3e8")) ) ) But with that I don't get background on emacsclient (even for

emacs lisp and c-mode: when am I in a comment region

余生长醉 提交于 2019-12-23 07:56:42
问题 I'd like to search for regular expressions within a c/c++ buffer, but I want to avoid expression matching a comment region. Is there a way using the c mode to know if a bunch of text is within a comment region (or a point is within a comment region)? 回答1: The way to figure that out is with syntax-ppss which works in C/C++ and most major modes. E.g. (null (nth 8 (syntax-ppss))) will be non-nil if and only if you're not within a string-or-comment. 回答2: (defun re-search-forward-not-in-comment

Customize interface for org-capture-templates

梦想的初衷 提交于 2019-12-23 03:26:48
问题 Started using org-mode and I've gotten to configuring the org-capture template. Would like to get a simple set-up going for starters. I've bound 'org-capture to C-c c so C-c c C gives me the org-capture-templates interface - supposedly a good way to configure a template. But how do I interact with this interface? Consulted the org-manual but haven't found mention how how the customize interface actually work ... 回答1: In the customize buffer click on INS button it is just below the Org Capture

Buffer menu to select a set of filenames in Emacs

烂漫一生 提交于 2019-12-22 22:57:52
问题 I have a directory "a" with a set of templates, for instance $ ls a b bcc cc ccdd I would like to implement a keyboard shortcut in Emacs that will show a buffer with the template names, similar to dired or buffer-menu and then be able to select a template name by using arrow keys or mouse. Then insert the selected template into the current buffer at point. How can this be done? 回答1: insert-file , bound to C-x i by default, can insert a file into your buffer at point, but it doesn't give you a

Extract the second level headline

為{幸葍}努か 提交于 2019-12-22 12:21:38
问题 For my global TODO list, I am showing breadcrumbs as suggested here : (concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ") to produce following: I would like to show only the second level of project breadcrumb. So in this case, I would only display [Project A] . I think if I can make a function that can extract the second level, I just need to prepend with %? so that [Tasks] does not appear for Tasks, but only project names would appear for Projects. What would be an

How to go back to previously defined function in Emacs Lisp?

冷暖自知 提交于 2019-12-22 10:50:08
问题 I have a function: (defun function-name (&optional args) ... <unknown content>) I redefine it with (defun function-name (&optional args) ... my own content) Can I somehow after some time remove my own version of function-name and stay with the first one? 回答1: No, you cannot . Save/Restore You can save the definition yourself before redefining the function: Common Lisp : (defparameter *old-def* (fdefinition 'function-name)) (defun function-name ...) ... (setf (fdefinition 'function-name) *old

Do stuff when selecting a window

不想你离开。 提交于 2019-12-22 09:57:04
问题 I've been looking through the available hooks, but none of them seems to be firing when you switch windows. What I'm trying to do, is activating a minor mode for the selected window: (defvar active-window (frame-selected-window)) (defun active-window-switch (&rest _) (when active-window (with-selected-window active-window (active-window-mode nil))) (setq active-window (frame-selected-window)) (active-window-mode t)) (define-minor-mode active-window-mode "Minor mode to distinguish the selected

Emacs: Set writeroom mode as default

久未见 提交于 2019-12-22 09:52:14
问题 I am new to emacs and I am wondering if I can set the writeroom-mode to always be on. I want it to be on as I start up emacs and as I open new buffers or switch between them. All help is highly appreciated! 回答1: So now that you've provided a link (albeit in your other question), I can see that the library provides a global minor mode which only turns itself on for a specific configurable set of major modes. The following will redefine the function which makes that decision, so that if the

Non-interactive emacs regex substitute

那年仲夏 提交于 2019-12-22 08:57:33
问题 Is there a (non-interactive) function in emacs lisp that replaces a matched regex in an arbitrary string? i.e. (sub regex search-string replace-string) as in (sub "[^.x/]" "beef./xxfoo" "") ;; => "./xx" 回答1: Yes, see function replace-regexp-in-string . Simple as that. And to replace matching text in a buffer, you have replace-regexp . The replacement does not need to be a literal string, but can involve retrieving parts of the regexp match and other manipulations. Use C-h f to see the doc for

Making a region-indent-function keep the region marked

故事扮演 提交于 2019-12-22 08:22:54
问题 I'm having trouble with haml-mode's region-indent-function , which I'm trying to reuse in another major mode. We're supposed to be able to cycle the region indentation by keeping the region marked after the haml-indent-region is being evaled, but it doesn't work as intended. After some hacking around, I've found out that throwing an error at the end of the function makes Emacs keep the region marked, as in this example: (defun haml-indent-region (start end) (save-excursion ...) (error "")) ;;