• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 18:00
CEST 00:00
KST 07:00
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Classic Games #3: Rogue vs Serral at BlizzCon9[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway13
Community News
SC4ALL $6,000 Open LAN in Philadelphia7Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues29LiuLi Cup - September 2025 Tournaments3Weekly Cups (August 25-31): Clem's Last Straw?39Weekly Cups (Aug 18-24): herO dethrones MaxPax6
StarCraft 2
General
Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues #1: Maru - Greatest Players of All Time Team Liquid Map Contest #21 - Presented by Monster Energy Classic Games #3: Rogue vs Serral at BlizzCon What happened to Singapore/Brazil servers?
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris RSL: Revival, a new crowdfunded tournament series WardiTV TL Team Map Contest #5 Tournaments Sparkling Tuna Cup - Weekly Open Tournament SC4ALL $6,000 Open LAN in Philadelphia
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
Pros React To: SoulKey's 5-Peat Challenge BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion ASL20 General Discussion BSL Team Wars - Bonyth, Dewalt, Hawk & Sziky teams
Tourneys
[IPSL] ISPL Season 1 Winter Qualis and Info! Is there English video for group selection for ASL [ASL20] Ro16 Group B [ASL20] Ro16 Group A
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread Borderlands 3 Nintendo Switch Thread Path of Exile General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread
Community
General
Canadian Politics Mega-thread US Politics Mega-thread Russo-Ukrainian War Thread The Big Programming Thread Things Aren’t Peaceful in Palestine
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
The Personality of a Spender…
TrAiDoS
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1299 users

More emacs VAssisting

Blogs > araav
Post a Reply
araav
Profile Blog Joined September 2004
Armenia1590 Posts
April 22 2009 14:47 GMT
#1
Yay, added three more Visual Assist features to my emacs. Two of them are not exactly what i wanted, but still better, much better than nothing.

This emacs thingie is really-really growing on me, its coolness and richeness are amazing!

Ok, about the added features.

Ctrl+Shift+V
This key combination pops a menu of last copied texts so you select one quickly and it's inserted. And this pasted chunk comes on top of copied things. When I started using Assist, this, along with Alt+o and Alt+m feature quickly became my top used features. I was so missing those.

After successfully implementing the Alt+o thing, I was constantly thinking about this one. I am very new in Emacs and I know those are easy things, but not for me.

Emacs has something similar to this paste menu, called "Paste from kill menu" in the "Edit" menu. But you know, when typing, it's not convenient to reach to mouse or press menu key combinations, it must be Ctrl+Shift+V, ok? How do I add new things for emacs? I do M-x ielm and the wanderful elisp interpreter appears. Her I can do whatever I want and at the end, when everything works, I just copy and paste to my .emacs.

First thing, after some trial and error, I got
(global-set-key [?\C-\S-v] 'do-paste-menu)
key combination to set up the keys to be calling the do-paste-menu function. Among some errors was that [?\C-V] was overriding the C+v too.

now my (defun do-paste-menu() ( print "hello" )) was printing my usual hello and it was already cool :-)
Next, I found from emcas include files that there was somthing called x-popup-menu. After reading its info it turned that this cool function was all I needed. Now
(defun do-paste-menu() ( let ((y (x-popup-menu t 'yank-menu))) (print y)))
was popping up the menu - my dream menu, but when I pressed it, nothing happened. Actually the content of the selected thing was prineted in the echo area. Not bad at all, but the quick replacement of 9print y) by (insert y) was inserting a lot of attributes along with the actual text. So I gave up at the moment and returned to it a couple of days later.
Long story short, my final function looks like this:
(defun do-paste-menu()
"Show and paste from menu"
(interactive)
(let* ((y (x-popup-menu t 'yank-menu)) (z (car y)))
(when (and z (> (length z) 0))
(set-text-properties 0 (length z) nil z)
(insert z))))

As it turned out, not y, but the car of y was holding the actual text and I stored it in z. And then if (when) there was anything there (the z part of and) and it it had a length of >0, then I removed its properties (set-text-properties 0 (length z) nil z) and inserted it! And voila! My ctrl+shift+v works!!!!!!!!!! Well, not exactly. In the ideal world it should also pop the pasted text and amke it my currently pasted guy and the list also contains duplicated texts, so there is still someting to work on. Will do that eventually.
The next thing, I know I did it all wrong, the menu item itself (the y guy) seems contains the actual pasting function too (emacs coolness), but I need to read up some stuff before being able to use it.

As for now, I already have the C+S+v's preliminary implementation and I am happy enough.

Alt+m
This again is one of my most favorite featrues of Visual assist. You press alt+m, the list of functions appears of an editable combo box, you then type in some letters and it selects the function from that combo box. It's so quick and easy, after some time you do not even remember the sequence of the functions. Not only you forget it, you don't even think about it, it becomes abstracted. Now one needs to be careful with this though. Indeed if you just type in functions regardless of their places, that would fuck up the structure of the object file and in some cases even the program's performance (this is quiet an advanced topic, so will not touch for now, go read some Drepper papers for that).
Back to the emacs. Apparently emacs' speedbar is a nice feature and it parses and dynamically updates the list of functions. But again... it's interface for this particular use case is too complcated. You need to
- switch to it (alt+zero for me)
- press +
- find your function
- press enter

As a result the list remains opened and a valuable vertical space is wasted. Though speedbar's added green overlay on top of the just visited function is sweet.

It turned out emacs already has a nice way of doing this and it's called imenu. Speedbar internally uses imenu's features to construct its items. Imenu has a feature of adding a menu item "Index" to the main menu, the contents of which is what I want. Imenu also offers a way of showing a menu for the M-x imenu command. It can have three values - Mouse event, Always, Never.
If it's bound to a mouse event, a menu is indeed appears. I want keyboard, so I selected "Always". It didn't work... what a pity. Again, I ended up with the following code -
;; go-to-definition-menu
(defun my-imenu-helper()
(let (index-alist
(result t)
alist)
;; Create a list for this buffer only when needed.
(while (eq result t)
(setq index-alist (imenu--make-index-alist))
(setq result (imenu--mouse-menu index-alist t))
(and (equal result imenu--rescan-item)
(imenu--cleanup)
(setq result t imenu--index-alist nil)))
result))

(defun my-imenu() (interactive) (imenu (my-imenu-helper)))
(global-set-key [?\M-\m] 'my-imenu)

The function my-imenu-handler was taken from imenu's codes and modified to meet my needs. The original function was bound to use mouse event which made it unusable as it was. So its modified coppy appears in my .emacs. The (imenu ....) call does the goto part to the place which the handler returns.

This works, I press Alt+M and the menu appears. This is good again, but it's again not what I really wanted. I want to have the filtering method - I want a combo box solution!

Alt+g
Or open the include file!
If you do Alt+g on line
#include "myfile.h"
and your cursor is somewhere between the "", visual assist opens the myfile.h. This again is a nice feature, which cuts a lot of speedbar usage.

After some ielming, I got the following code working for me:
(defun hoper-src(env) (let ((p (getenv env))) (if p (concat (file-name-as-directory p) "hoper/src") nil)))
(defun src-path () (list "." (hoper-src "LOCAL_BUILD") (hoper-src "GLOBAL_BUILD")))
(defun line-incl-fln(str) (when (string-match "^[[:space]*#[[:space]*include[[:space]+[\"\<]\\(.*\\)[\"\>][[:space]*$" str)
(match-string-no-properties 1 str)))
(defun incl-fln() (line-incl-fln (thing-at-point 'line)))
(defun open-incl-fln(str) (let ((fln (locate-file str (src-path)))) (find-file fln)))
(defun open-include-file()
"Open the C/C++ include file under cursor"
(interactive)
(let ((fln (incl-fln))) (when fln (open-incl-fln fln))))
(global-set-key [M-\kp-multiply] 'open-include-file)
(global-set-key [M-\kp-decimal] 'open-include-file)

Some things to mention.
(src-path) returns the list of directories to search for a file. It always includes the current directory and also I've added the directories for my company's project, which I mention as "hoper" (intentional change).
The funtion line-incl-fln parses the argument of form #include "file" or and returns the FILE part (well, it also accepts "file> and &lt file", but it's a feature, not a bug [while blogger.com's complaining about my &ltfile incomplete key and eating it through the end of line is indeed a bug - wtf]).
The rest is just taking the current line (thing-at-point 'line), and searching it through find-file.
I could not bind it to Alt+g, so I went with both Alt+Keypad * and Alt+"Keypad .". The . one is similar to the default Alt+. aka goto definition and the * one is similar to goto current line of the visual studio debugger. Although totally different, but somehow it looked at least familiar for me.

Off now, will continue later...

The flower that blooms in adversity is the most rare and beautiful of all.
Please log in or register to reply.
Live Events Refresh
BSL Team Wars
19:00
Playoff - 4th vs 3rd
Team Bonyth vs Team Sziky
ZZZero.O82
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason127
Nathanias 64
Lillekanin 11
StarCraft: Brood War
ZZZero.O 82
sSak 30
NaDa 14
Artosis 0
Dota 2
NeuroSwarm123
LuMiX1
Counter-Strike
fl0m1579
Stewie2K521
Heroes of the Storm
Liquid`Hasu546
Other Games
Grubby3741
FrodaN2523
ToD415
KnowMe185
Sick176
SortOf125
Organizations
Other Games
BasetradeTV36
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• RyuSc2 42
• musti20045 41
• StrangeGG 37
• Sammyuel 7
• LaughNgamezSOOP
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• HerbMon 23
• RayReign 1
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota22982
League of Legends
• Doublelift5331
Other Games
• imaqtpie1191
• Scarra985
Upcoming Events
Afreeca Starleague
12h
Snow vs Sharp
Jaedong vs Mini
Wardi Open
13h
OSC
1d 2h
Sparkling Tuna Cup
1d 12h
Afreeca Starleague
1d 12h
Light vs Speed
Larva vs Soma
PiGosaur Monday
2 days
LiuLi Cup
2 days
RSL Revival
3 days
Maru vs Reynor
Cure vs TriGGeR
The PondCast
3 days
RSL Revival
4 days
Zoun vs Classic
[ Show More ]
Korean StarCraft League
5 days
RSL Revival
5 days
[BSL 2025] Weekly
5 days
BSL Team Wars
5 days
RSL Revival
6 days
Online Event
6 days
Liquipedia Results

Completed

Proleague 2025-09-10
SEL Season 2 Championship
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
RSL Revival: Season 2
Maestros of the Game
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1

Upcoming

2025 Chongqing Offline CUP
BSL Polish World Championship 2025
IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
SC4ALL: StarCraft II
EC S1
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.