• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:21
CET 13:21
KST 21:21
  • 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
Intel X Team Liquid Seoul event: Showmatches and Meet the Pros9[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3
Community News
Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win52025 RSL Offline Finals Dates + Ticket Sales!10BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION1Crank Gathers Season 2: SC II Pro Teams10Merivale 8 Open - LAN - Stellar Fest4
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" Intel X Team Liquid Seoul event: Showmatches and Meet the Pros Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win Weekly Cups (Oct 13-19): Clem Goes for Four DreamHack Open 2013 revealed
Tourneys
Kirktown Chat Brawl #9 $50 8:30PM EST 2025 RSL Offline Finals Dates + Ticket Sales! SC4ALL $6,000 Open LAN in Philadelphia Merivale 8 Open - LAN - Stellar Fest Crank Gathers Season 2: SC II Pro Teams
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment
Brood War
General
Ladder Map Matchup Stats Map pack for 3v3/4v4/FFA games BW General Discussion SnOw's ASL S20 Finals Review [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[ASL20] Grand Finals Small VOD Thread 2.0 The Casual Games of the Week Thread BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION
Strategy
PvZ map balance Current Meta How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Path of Exile Dawn of War IV Beyond All Reason Stormgate/Frost Giant Megathread 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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Big Programming Thread YouTube Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece Korean Music Discussion Series you have seen recently...
Sports
TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion MLB/Baseball 2023 2024 - 2026 Football Thread NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Career Paths and Skills for …
TrAiDoS
KPDH "Golden" as Squid Game…
Peanutsc
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1165 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
Epic.LAN
12:00
Epic.LAN 46 Playoffs Stage
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Reynor 594
BRAT_OK 96
Lowko91
Rex 89
StarCraft: Brood War
Hyuk 1610
PianO 571
Barracks 384
Last 338
ToSsGirL 39
zelot 35
HiyA 21
Terrorterran 15
Shine 10
910 1
[ Show more ]
sorry 0
Dota 2
XcaliburYe648
ODPixel536
canceldota218
Counter-Strike
PGG 132
Other Games
singsing1653
B2W.Neo1363
DeMusliM281
Hui .166
Mew2King37
nookyyy 6
Organizations
Counter-Strike
PGL11956
Other Games
gamesdonequick791
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Gemini_19 28
• Adnapsc2 5
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• Ler65
League of Legends
• Jankos3310
Other Games
• WagamamaTV197
Upcoming Events
BSL Team A[vengers]
1h 40m
Dewalt vs ZeLoT
UltrA vs ZeLoT
SC4ALL
1h 40m
SC4ALL
1h 40m
BSL 21
6h 40m
BSL Team A[vengers]
1d 1h
Cross vs Sobenz
Sziky vs IcaruS
SC4ALL
1d 2h
SC4ALL
1d 2h
BSL 21
1d 6h
Replay Cast
1d 20h
Wardi Open
1d 23h
[ Show More ]
Monday Night Weeklies
2 days
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
Replay Cast
3 days
WardiTV Korean Royale
3 days
The PondCast
4 days
Korean StarCraft League
6 days
CranKy Ducklings
6 days
Liquipedia Results

Completed

CSL 2025 AUTUMN (S18)
CranK Gathers Season 2: SC II Pro Teams
Eternal Conflict S1

Ongoing

BSL 21 Points
BSL 21 Team A
C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
SC4ALL: Brood War
SC4ALL: StarCraft II
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025

Upcoming

YSL S2
BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 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.