• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 17:48
CEST 23:48
KST 06:48
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
[BSL20] Non-Korean Championship 4x BSL + 4x China1Flash Announces Hiatus From ASL63Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22Esports World Cup 2025 - Final Player Roster16
StarCraft 2
General
Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
SC uni coach streams logging into betting site Player “Jedi” cheat on CSL Flash Announces Hiatus From ASL BW General Discussion Practice Partners (Official)
Tourneys
[BSL20] Non-Korean Championship 4x BSL + 4x China CSL Xiamen International Invitational The Casual Games of the Week Thread [BSL20] Grand Finals - Sunday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
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 Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Summer Games Done Quick 2025! Trading/Investing Thread Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 606 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: ProLeague
18:00
Grand Finals - bo9
Dewalt vs Bonyth
ZZZero.O625
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Livibee 95
ProTech84
StarCraft: Brood War
ZZZero.O 625
Terrorterran 26
League of Legends
Grubby4771
Dendi1544
Counter-Strike
fl0m1720
Super Smash Bros
Mew2King218
Chillindude101
Westballz51
Heroes of the Storm
Khaldor832
Liquid`Hasu679
Other Games
summit1g5289
FrodaN2965
tarik_tv1849
mouzStarbuck321
Pyrionflax211
ViBE111
elazer105
Organizations
Other Games
gamesdonequick44472
EGCTV1256
BasetradeTV46
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• musti20045 66
• Adnapsc2 22
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• 3DClanTV 78
• blackmanpl 10
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Ler149
League of Legends
• masondota2840
Other Games
• imaqtpie2366
• Shiphtur371
Upcoming Events
Wardi Open
13h 12m
Replay Cast
1d 2h
Sparkling Tuna Cup
1d 12h
WardiTV European League
1d 18h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
2 days
The PondCast
2 days
WardiTV European League
2 days
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
Replay Cast
3 days
RSL Revival
3 days
ByuN vs SHIN
Clem vs Reynor
Replay Cast
4 days
[ Show More ]
RSL Revival
4 days
Classic vs Cure
FEL
4 days
RSL Revival
5 days
FEL
5 days
FEL
5 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
FEL
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
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
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.