I'm using elscreen in my GNU Emacs 24.2.1
Currently, when i split my window, I have a same tab panel in each half:
elscreen http://i.zlowiki.ru/121101_0f30ebba.png/800
Note that the two lower windows have the same tabs as the largest one.
How can I remove these two duplicates, and keep only the top one?
If it is too hard, what another alternative could be used for GNU screen?
Here's something to technically do what you asked:
(setq elscreen-display-tab nil) ; disable tabs display
;; get-alist was removed somewhere along the line
;; You can try substituting all instances of get-alist with assoc-default
;; instead of using defalias and see if that works; I haven't tried.
(defalias 'get-alist 'assoc-default) ; get-alist is gone
;; Put tabs display in your frame title bar instead.
(defun elscreen-frame-title-update ()
(when (elscreen-screen-modified-p 'elscreen-frame-title-update)
(let* ((screen-list (sort (elscreen-get-screen-list) '<))
(screen-to-name-alist (elscreen-get-screen-to-name-alist))
(title (concat "| " (mapconcat
(lambda (screen)
(format "%d%s %s |"
screen (elscreen-status-label screen)
(get-alist screen screen-to-name-alist)))
screen-list " "))))
(if (fboundp 'set-frame-name)
(set-frame-name title)
(setq frame-title-format title)))))
(eval-after-load "elscreen"
'(add-hook 'elscreen-screen-update-hook 'elscreen-frame-title-update))
I'm sure it's not what you had in mind, but hey, it's at the VERY top now and only at the top.
Take a look at http://www.emacswiki.org/emacs/ElscreenSeparateBufferLists modifies the operation of elscreen slightly borrowing from escreen. It allows the list of tabs to differ on each buffer.
How about using elscreen-tab plugin?
This plugins is created to resolve what you are annoyed with.
You can install via melpa.
Related
this is my first question, so apologies for breaking any rules.
I've just started writing some functions in elisp to help me navigate certain types of text files more efficiently. To make these accessible, I've added some buttons to the tool-bar. As it's now becoming busy, I'd like to either: 1) move some of these additional buttons to a second line; or 2) instantiate a second tool-bar that could be placed somewhere else in the frame (either under the existing tool-bar, or perhaps vertically along the side where the scrollbar is).
I've searched high and low but am unable to find an existing example of this and, as I don't yet really know what I'm doing, I wonder if somebody has a code snippet from which I might start to hack a solution together.
Many thanks in advance.
System: CentOS 5/6, emacs for linux 23.1
Edit:
Thanks for the comment, William. Here's a simple example representing what my tool-bar code might do:
;
; functions used by the toolbar
;
;
(defun copy-paste-whole-line ()
"copies and pastes the whole of the current into a new line underneath"
(interactive)
(beginning-of-line)
(set-mark (point))
(end-of-line)
(setq temp (buffer-substring (region-beginning) (region-end)))
(message " copying: %s" temp )
(newline)
(insert temp))
;
;
; population of the toolbar:
;
;
(when (find-image '((:type xpm :file "copy_paste_line.xpm")))
(unless tool-bar-mode (tool-bar-mode 1))
; (setq tool-bar-map (make-sparse-keymap)) ; <- uncomment this line to have only this button present
(tool-bar-add-item
"copy_paste_line"
'copy-paste-whole-line
'copy-paste-whole-line
:help "copies and pastes the whole of the current line into a new line underneath"))
so, as you can see (actually, I'm not allowed to post images until I have 10 reputation points, so you won't be able to see), the code adds an extra button to the end of the existing tool-bar buttons. I believe this to be a reasonable way to achieve this, but I'm not an experienced elisp programmer, so if you think it's poorly written, please comment - I'd like to understand why... :)
If I only had 1 button, it would be ok like that, however, I have multiple buttons. I would, thus, like to add them to a second instance of a similar tool-bar (or, perhaps a vertical one placed where the scrollbars are).
Thanks again for any input.
Frame parameter tool-bar-lines is supposed to control this. You can, for instance, customize option default-frames-alist if you want to change the number of tool-bar rows to 2 or 3 everywhere. Or you can do this on a mode-by-mode or frame-by-frame basis. You can, for instance, use M-: (set-frame-parameter nil 'tool-bar-lines 3).
Depending on your platform (and toolkit), the behavior might be variable. See the Elisp manual, node Layout Parameters and node Tool Bars.
I believe you are out of luck. It seems to me that (at least on ubuntu and cygwin) only one row of buttons in the tool-bar is supported.
Here is what I have tried without luck on both systems:
(progn
(set-frame-parameter nil 'tool-bar-lines 3)
(loop for i from 1 upto 20 do
(setcdr tool-bar-map (cons (cadr tool-bar-map) (cdr tool-bar-map)))))
The following picture shows what I get:
The other buttons appear in a pull-down menu if you click on the little triangle at the right end of the toolbar:
You can restore the old tool-bar with the following commands:
(progn
(setq tool-bar-map (make-sparse-keymap))
(tool-bar-setup))
Finally, I have 3 rows of buttons. This is possible with emacs-w32:
So it is the gtk+ / nextstep problem.
Emacs tends to open two horizontally separated windows, one on top of the other (I think windows is the proper emacs term). Since I am working with a wide screen I find it easier and better to work with two vertically separated windows, arranged side by side within the emacs frame.
I know how to open a new vertically separated window using C-x 3 but how do you rearrange windows that emacs opens itself (for example when M-x compile is invoked opening a compilation/debugging window) from horizontal to vertical?
I had the same problem, this is what I currently use. Just drop it into your Emacs init file:
;; The default behaviour of `display-buffer' is to always create a new
;; window. As I normally use a large display sporting a number of
;; side-by-side windows, this is a bit obnoxious.
;;
;; The code below will make Emacs reuse existing windows, with the
;; exception that if have a single window open in a large display, it
;; will be split horisontally.
(setq pop-up-windows nil)
(defun my-display-buffer-function (buf not-this-window)
(if (and (not pop-up-frames)
(one-window-p)
(or not-this-window
(not (eq (window-buffer (selected-window)) buf)))
(> (frame-width) 162))
(split-window-horizontally))
;; Note: Some modules sets `pop-up-windows' to t before calling
;; `display-buffer' -- Why, oh, why!
(let ((display-buffer-function nil)
(pop-up-windows nil))
(display-buffer buf not-this-window)))
(setq display-buffer-function 'my-display-buffer-function)
Take a look at the split-height-threshold and the split-height-threshold variables, both customizable.
For further information on what values they take, C-h f split-window-sensibly RET. This Emacs Lisp touches the topic superficially.
This affects how display-buffer works, which probably compile and many other commands use.
Here's my solution:
(defun split-window-prefer-side-by-side (&optional window)
(let ((split-height-threshold (and (< (window-width window)
split-width-threshold)
split-height-threshold)))
(split-window-sensibly window)))
(setq split-window-preferred-function 'split-window-prefer-side-by-side)
This still consults split-*-threshold variable values, just prefers side-by-side windows when both splitting directions are acceptable.
I use GNU EMACS on multiple monitors from a Windoze PC via VNC.
(Currently 5 - 4 big, 1 the small monitor on my tablet PC. Two vertical 1200x1920, two horizontal 1920x1200, plus the small.)
The way I am currently doing this is to run a separate VNC on each monitor. I then open a single emacs, and use make-frame-other-display to open emacs' frames in the other VNC window.
To make things more complicated - I run the VNCs on an up-to-date Ubuntu system, but I run the emacs on a quite out of date machine where the rest of the build tools live. I.e. the VNC displays are not local to the same machine as emacs.
Rather than xhost+, I open an xterm in each of the VNCs, and ssh to the machine running emacs. This creates DISPLAYS of the form localhost:16.0. I then use make-frame-on-display using these localhost DISPLAYs.
This gets confusing.
It helps if I leave an "echo $DISPLAY" in the xterm windows. Or chamnge the xterm's title.
I'd like to similarly change the EMACS' frames' titles, to reflect what each frame things is its current DISPLAY. But doing
(defvar frame-title-specific-ag "emacs"
"title element from frame-title-format that is specific to a particular emacs instance; andy glew")
(setq frame-title-format
(list
"frame=%F "
(format "%s" frame-title-specific-ag)
" " 'system-name
" DISPLAY="
(getenv "DISPLAY")
" %b"
" " (format "pid:%d" (emacs-pid))
" user:"(user-login-name))
)
only gets the DISPLAY variable for the entire emacs.
Q: is there a way to find out the display associated with any particular frame?
To get the display name for the current frame, use
(frame-parameter nil 'display)
or replace nil with a specific frame to get the name of its display instead of the current one. For example, use this to show the display in the title:
(setq frame-title-format
'("DISPLAY=" (:eval (frame-parameter nil 'display))))
Note that it is important that this form is completely quoted, so the list that is used has an :eval which tells Emacs to run the code whenever it renders a frame title. Without that, you might be tempted to write something like:
(setq frame-title-format
(list "DISPLAY=" (frame-parameter nil 'display)))
but this doesn't work. The problem is that the function call happens immediately when this form is evaluated, and the result is a list holding a particular string, which is the name of whatever frame was in effect this evaluation happened, and the string will not change magically.
Eli Barzilay pointed us to
(frame-parameter nil 'display)
which is 90% of the way there.
The following puts the display associated with the currently selected frame in its frame title.
(setq frame-title-format
'(
"DISPLAY="
(:eval (frame-parameter nil 'display))
)
)
Glew: This puts the display of the currently selected frame, at the time the frame is created
(e.g. via make-frame-on-display) in the
title. Since this may be a different frame, in a completely different
display, it is not always what is wanted.
The unquoted, un-:eval'ed, form, puts the display of the currently selected frame,
at the time the setq is evaluated, in the title. This is even less of what is wanted.
Here is what I ended up with:
I set the default frame-title-format as above. But I do bnot really use it because I
hook the following:
(defun ag-set-frame-title (frame)
"set frame-title to glew preference, optional arg FRAME / default nil (currently selected frame)"
(interactive)
;; TBD: make-variable-frame-local is deprecated in more recent versions of emacs
;; than the antiquated version at my work. use modify-frame-parameters instead
(let (x)
(setq x
(concat
(or frame-title-specific-ag "emacs")
" " system-name
" DISPLAY=" (frame-parameter frame 'display)
" " (format "pid:%d" (emacs-pid))
" user:" (user-login-name)
;;" " (buffer-name)
)
)
(modify-frame-parameters frame (list (cons 'title x)))
)
)
;; TBD: this old emacs does not have modern hooks
(setq after-make-frame-functions '(ag-set-frame-title))
For good measure:
(defun ag-fix-frame-titles ()
"run ag-set-frame-title on frame-lits"
(interactive)
(mapc 'ag-set-frame-title (frame-list))
)
(ag-fix-frame-titles)
NOTE: per comment string it is possible that the fix described here is only needed on an old version of emacs, such as 21.4.1. #EliBarzilay says not needed on whatever version of emacs he is using.
Subtract points all you want, folks. Truth.
I'm attempting to switch from Vim to Emacs, but I'm tearing my hair out trying to configure it to treat tabs how I wish. I require:
Inserted "tabs" to be expanded into two spaces. Emacs stubbornly sticks to eight, no matter what I do.
Tabs (i.e. real \t characters) to be represented on screen by two spaces.
Pressing TAB should insert a tab at the cursor rather than indent the entire line. Currently, I press TAB anywhere and Emacs destroys all whitespace at the start of the line; this is the most infuriating thing so far.
My current ~/.emacs reads
(setq standard-indent 2)
(setq-default indent-tabs-mode nil)
but I have tried no end of suggested configurations from the web, none of which have done what they said they would. (Does the API constantly change? I'm using GNU Emacs 23.1.1, apparently.)
Emacs has extremely flexible support for handling indentation. Generally the mode that you are in dictates how they work - so if you're working on a C file then the way that pressing tab works will be different than if you're working on a Python file.
So it does depend which mode you're working in, which will limit the answers you get. In most cases I would recommend that you don't fight against it - for me the indentation behaviour is one of the best features of emacs. However, you do need to spend the time to customize it for yourself.
To change the way that tabs are displayed you need to set tab-width to 2. If you're editing Java or C style code then it sounds like you want to turn off all the nice indentation features by these to NIL:
c-tab-always-indent
c-syntactic-indentation
indent-tabs-mode
I suggest you set these through the customization interface. If you use "M-x customize-group RET C" then you can see the various settings for C mode.
If you're editting different types of files then the instructions will be different.
Perhaps emacs is in the wrong mode for your file. You could try doing "M-x fundamental-mode" to see if you prefer the behaviour there.
;; * Inserted "tabs" to be expanded into two spaces. Emacs stubbornly
;; sticks to eight, no matter what I do.
;; * Tabs (i.e. real \t characters) to be represented on screen by two
;; spaces.
(setq-default tab-width 2)
;; * Pressing TAB should insert a tab at the cursor rather than indent
;; the entire line. Currently, I press TAB anywhere and Emacs
;; destroys all whitespace at the start of the line; this is the
;; most infuriating thing so far.
(setq-default indent-tabs-mode t)
(mapcar (lambda (hooksym)
(add-hook hooksym
(lambda ()
(kill-local-variable 'indent-tabs-mode)
(kill-local-variable 'tab-width)
(local-set-key (kbd "TAB") 'self-insert-command))))
'(
c-mode-common-hook
;; add other hook functions here, one for each mode you use :-(
))
;; How to know the name of the hook function? Well ... visit a file
;; in that mode, and then type C-h v major-mode RET. You'll see the
;; mode's name in the *Help* buffer (probably on the second line).
;; Then type (e.g.) C-h f python-mode; you'll see blather about the
;; mode, and (hopefully) somewhere in there you'll see (again e.g.)
;; "This mode runs the hook `python-mode-hook', as the final step
;; during initialization."
This should get you most of what you want. You'll probably have to customize some other programming modes you commonly use.
(defun insert-tab ()
"self-insert-command doesn't seem to work for tab"
(interactive)
(insert "\t"))
(setq indent-line-function 'insert-tab) ;# for many modes
(define-key c-mode-base-map [tab] 'insert-tab) ;# for c/c++/java/etc.
(setq-default tab-width 2)
I want to have sort of indiacator at left side of the line wherever I have in the source code
#TODO: some comment
//TODO: some comments
The indicator could be a just mark and I already enabled line numbers displayed at emacs.
This command will do something like you want.
(defun annotate-todo ()
"put fringe marker on TODO: lines in the curent buffer"
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "TODO:" nil t)
(let ((overlay (make-overlay (- (point) 5) (point))))
(overlay-put overlay 'before-string (propertize "A"
'display '(left-fringe right-triangle)))))))
You can customize the bitmap as desired.
To get this to apply to all files, you could add it to the 'find-file-hooks
(add-hook 'find-file-hooks 'annotate-todo)
Or, if you want it just for certain modes, you could add it to those mode hooks.
See Fringes, The 'display' Property, Overlays, and most importantly the before-string property.
Note: The code was updated 27/02/2010 to use overlays instead of directly adding text properties to the current text.
I like the approach described in this post on emacs-fu, which adds TODO/FIXME/... to the font-lock settings of the modes where you need it. In contrast to Trey's approach this should highlight the words as you type, whereas his approach should only highlight them when you open a file (or do I get this wrong).
Anyway its up to you. A good google search gives you probably even more ideas: http://www.google.com/search?q=emacs+highlight+todo
Update: Your question has already been answered: Emacs, highlight all occurences of a word