vi_rc YankLines( void ) { range r; GetLineRange( &r, GetRepeatCount(), CurrentPos.line ); return( Yank( &r ) ); } /* YankLines */
/* * AddSelRgnToSavebuf - copy selected text to savebuf */ vi_rc AddSelRgnToSavebuf( void ) { char buf[] = "0"; range r; vi_rc rc; rc = GetSelectedRegion( &r ); if( rc != ERR_NO_ERR ) { return( rc ); } NormalizeRange( &r ); SetSavebufNumber( buf ); return( Yank( &r ) ); }
bool wxExEx::Command(const wxString& command) { if (command.empty() || !command.StartsWith(":")) { return false; } bool result = true; if (command == ":") { m_Frame->GetExCommand(this, command); return true; } else if (command == ":$") { m_STC->DocumentEnd(); } else if (command == ":close") { wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_CLOSE); wxPostEvent(wxTheApp->GetTopWindow(), event); } else if (command == ":d") { return Delete(1); } else if (command.StartsWith(":e")) { wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_OPEN); if (command.Contains(" ")) { event.SetString(command.AfterFirst(' ')); } wxPostEvent(wxTheApp->GetTopWindow(), event); } else if (command.StartsWith(":g")) { result = CommandGlobal(command.AfterFirst('g')); } else if (command == ":n") { wxExSTC* stc = m_Frame->ExecExCommand(ID_EDIT_NEXT); if (stc != NULL) { if (m_Macros.IsPlayback()) { m_STC = stc; } } else { result = false; } } else if (command == ":prev") { wxExSTC* stc = m_Frame->ExecExCommand(ID_EDIT_PREVIOUS); if (stc != NULL) { if (m_Macros.IsPlayback()) { m_STC = stc; } } else { result = false; } } else if (command == ":q") { wxCloseEvent event(wxEVT_CLOSE_WINDOW); wxPostEvent(wxTheApp->GetTopWindow(), event); } else if (command == ":q!") { wxCloseEvent event(wxEVT_CLOSE_WINDOW); event.SetCanVeto(false); wxPostEvent(wxTheApp->GetTopWindow(), event); } else if (command.StartsWith(":r")) { wxString arg(command.AfterFirst(' ')); arg.Trim(false); // from left if (arg.StartsWith("!")) { if (m_Process == NULL) { m_Process = new wxExProcess; } m_Process->Execute(arg.AfterFirst('!'), wxEXEC_SYNC); m_Process->HideDialog(); m_STC->AddText(m_Process->GetOutput()); } else { wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, ID_EDIT_READ); event.SetString(arg); wxPostEvent(wxTheApp->GetTopWindow(), event); } } // e.g. set ts=4 else if (command.StartsWith(":set ")) { result = CommandSet(command.Mid(5)); } else if (command.StartsWith(":w")) { if (command.Contains(" ")) { wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_SAVEAS); event.SetString(command.AfterFirst(' ')); wxPostEvent(wxTheApp->GetTopWindow(), event); } else { wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_SAVE); wxPostEvent(wxTheApp->GetTopWindow(), event); } } else if (command == ":x") { wxPostEvent(wxTheApp->GetTopWindow(), wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, wxID_SAVE)); wxPostEvent(wxTheApp->GetTopWindow(), wxCloseEvent(wxEVT_CLOSE_WINDOW)); } else if (command == ":y") { Yank(1); } else if (command.Last() == '=') { const int no = ToLineNumber(command.AfterFirst(':').BeforeLast('=')); if (no == 0) { return false; } m_Frame->ShowExMessage(wxString::Format("%d", no)); return true; } else if (command.StartsWith(":!")) { if (m_Process == NULL) { m_Process = new wxExProcess; } m_Process->Execute(command.AfterFirst('!')); } else if (command.AfterFirst(':').IsNumber()) { m_STC->GotoLineAndSelect(atoi(command.AfterFirst(':').c_str())); } else { result = CommandRange(command.AfterFirst(':')); } if (result) { SetLastCommand(command); MacroRecord(command); } else { wxBell(); } return result; }
bool wxExEx::CommandRange(const wxString& command) { const wxString tokens("dmsyw><"); // If address contains markers, filter them. if (command.Contains("'")) { const wxString markerfirst = command.AfterFirst('\''); const wxString markerlast = command.AfterLast('\''); if ( tokens.Contains(markerfirst.Left(1)) || tokens.Contains(markerlast.Left(1))) { return false; } } // [address] m destination // [address] s [/pattern/replacement/] [options] [count] wxStringTokenizer tkz(command, tokens); if (!tkz.HasMoreTokens()) { return false; } const wxString address = tkz.GetNextToken(); const wxChar cmd = tkz.GetLastDelimiter(); wxString begin_address; wxString end_address; if (address == ".") { begin_address = address; end_address = address; } else if (address == "%") { begin_address = "1"; end_address = "$"; } else if (address == "*") { std::stringstream ss; ss << m_STC->GetFirstVisibleLine() + 1; begin_address = wxString(ss.str()); std::stringstream tt; tt << m_STC->GetFirstVisibleLine() + m_STC->LinesOnScreen() + 1; end_address = wxString(tt.str()); } else { begin_address = address.BeforeFirst(','); end_address = address.AfterFirst(','); } if (begin_address.empty() || end_address.empty()) { return false; } switch (cmd) { case 0: return false; break; case 'd': return Delete(begin_address, end_address); break; case 'm': return Move(begin_address, end_address, tkz.GetString()); break; case 's': { wxStringTokenizer next(tkz.GetString(), "/"); if (!next.HasMoreTokens()) { return false; } next.GetNextToken(); // skip empty token const wxString pattern = next.GetNextToken(); const wxString replacement = next.GetNextToken(); return Substitute(begin_address, end_address, pattern, replacement); } break; case 'y': return Yank(begin_address, end_address); break; case 'w': return Write(begin_address, end_address, tkz.GetString()); break; case '>': return Indent(begin_address, end_address, true); break; case '<': return Indent(begin_address, end_address, false); break; default: wxFAIL; return false; } }